0

I have code like this:

class Direction(Enum):
    ...
    def rotateClockwise(cls, direction): 

Is it possible to add a type requirement of the class Direction within the class itself? I ask because when I try using the normal decorator syntax, it says Direction isn't defined, which makes sense.

I tried this, and would like to be able to do something to the effect of this:

class Direction(Enum):
    ...
    def rotateClockwise(cls, direction: Direction) -> Direction: 

So If there is a correct way, what is it?

Dmich
  • 130
  • 6
  • Annotations are simply text explanations. The types or output are in no way enforced by the act of annotating. – dfundako Jun 08 '18 at 20:13
  • For 3.6 or earlier, `"Direction"` is good enough for mypy and other static type checkers, and hopefully you don't care what you end up with at runtime. For 3.7, [things are improved a bit](https://www.python.org/dev/peps/pep-0563/), but since 3.7 is still in beta, there's a good chance you can't require it. – abarnert Jun 08 '18 at 20:22

0 Answers0