Recursive type annotations
Nagy László Zsolt
gandalf at shopzeus.com
Wed Jun 8 09:31:18 EDT 2016
>> pass
>>
>> NameError: name 'Test' is not defined
> I think you can fix this by using a string annotation as follows:
>
> class Test:
> def test(self, child: "Test"):
> pass
Yes, you are right. It is not directly written in the official
documentation ( https://docs.python.org/3/library/typing.html ), but it
is in the PEP 0484, section "Forward references".
Thanks!
Laszlo
More information about the Python-list
mailing list