In Python 3.5 you need to write
self.some_attribute = None # type: AnotherClass
Starting with Python 3.6, a new type of syntax has been added for variables ( PEP 526 ):
self.some_attribute: AnotherClass = None
This is likely to cause every type checking system to complain, because None is not really an instance of AnotherClass. Instead, you can use typing.Union[None, AnotherClass]either shorthand:
from typing import Optional
...
self.some_attribute: Optional[AnotherClass] = None
source
share