Recursive type annotations

Nagy László Zsolt gandalf at shopzeus.com
Wed Jun 8 09:02:23 EDT 2016


class Test:
    def test(self, child : Test):
        pass

NameError: name 'Test' is not defined

I understand that the class "Test" is not defined until the class
definition is executed. But it is very very common to build recursive
data structures, and I have concrete use case where the IDE did not
recognize the type of the argument, and as a result it forgot to rename
some method calls when I auto-refactored the name of the method.

I'm not an expert, but I believe that these annotations are not used by
the byte compiler for anything. This is just pure syntax introduced for
the person who reads the code.

Is there a known obsticle that would prevent us from detecting recursive
type annotations? (E.g. bind the annotation to the class that is being
defined.)

Thanks,

   Laszlo




More information about the Python-list mailing list