0

I have defined an abstract class like so:

class Fruits(ABC):
   @abstractmethod
   def eat(self):
       dosomething
   @staticmethod
   def helper(apple: Fruits):
       apple.eat()
       dosomethingelse 

However I am getting undefined name "Fruits" for the static method helper. I wonder what I am doing incorrectly here.

Keith
  • 119
  • 5
  • 1
    This has **nothing to do with** either abstract methods or static methods. It is **only** a problem caused by the type annotation, which incidentally is **completely optional** in Python and has **no effect** on what can actually be passed at runtime (it is used by IDEs and third-party type checkers). – Karl Knechtel Jan 29 '23 at 22:41
  • At beginning of the code add line `from __future__ import annotations`. Details about it are at https://peps.python.org/pep-0563/ – Michael Butscher Jan 29 '23 at 22:44
  • This is solved by Self type in Python 3.11. https://rednafi.github.io/reflections/self-type-in-python.html – Abhijit Sarkar Jan 29 '23 at 22:46

0 Answers0