Recursive type annotations

Jon Ribbens jon+usenet at unequivocal.co.uk
Wed Jun 8 09:11:24 EDT 2016


On 2016-06-08, Nagy László Zsolt <gandalf at shopzeus.com> wrote:
> class Test:
>     def test(self, child : Test):
>         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



More information about the Python-list mailing list