0

I have two classes that reference each other in function input type declaration.

class Foo:
 def some_func(self, x:Bar):
  pass #Does Something

class Bar:
 def some_other_func(self, x:Foo):
  pass #Does something else entirely

Python won't let me run the code with either order of Foo or Bar there is a reference error. I tried looking at putting them in separate files, but I am unsure if that would solve the issue as they are still dependent on each other. I am not sure how I would pre-emptively declare the class type either.

  • 1
    I've closed your question as a duplicate even though it's not *exactly* the same because the same solutions apply (i.e. `from __future__ import annotations` or use a string instead). If there are any edge cases it doesn't cover, LMK and I'll be happy to reopen. FYI, to find it, I googled `python class typing NameError`. – wjandrea Jul 13 '22 at 02:20
  • @wjandrea That was a really easy fix and kinda feels dumb that I had to do that in the first place. you would think it would be an automatic feature. (The post you linked did seem to imply that it is intended for a future version but still) – ExodusSolis Jul 13 '22 at 02:39

0 Answers0