Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #109680

Re: Recursive type annotations

From Ian Kelly <ian.g.kelly@gmail.com>
Newsgroups comp.lang.python
Subject Re: Recursive type annotations
Date 2016-06-08 08:58 -0600
Message-ID <mailman.81.1465397951.2306.python-list@python.org> (permalink)
References <8e439d4f-182d-334d-ffbe-8c39856cdd33@shopzeus.com> <mailman.77.1465390948.2306.python-list@python.org> <slrnnlg6bs.6f8.jon+usenet@sable.unequivocal.co.uk> <7de91f01-4b8c-8f29-294a-4f2f6909bc89@shopzeus.com> <CALwzid=AJDKFZG=j7Lw3EqGdnWkNiEUuP2Ceuo7xT_c8ybd-1A@mail.gmail.com>

Show all headers | View raw


On Wed, Jun 8, 2016 at 7:31 AM, Nagy László Zsolt <gandalf@shopzeus.com> wrote:
>
>>>         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".

That link specifically documents the typing module. Forward references
don't really have anything to do with the typing module and are best
covered by the documentation of the static checker in use. Here's
where the MyPy documentation covers it:

http://mypy.readthedocs.io/en/latest/kinds_of_types.html#class-name-forward-references

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Recursive type annotations Nagy László Zsolt <gandalf@shopzeus.com> - 2016-06-08 15:02 +0200
  Re: Recursive type annotations Jon Ribbens <jon+usenet@unequivocal.co.uk> - 2016-06-08 13:11 +0000
    Re: Recursive type annotations Nagy László Zsolt <gandalf@shopzeus.com> - 2016-06-08 15:31 +0200
    Re: Recursive type annotations Ian Kelly <ian.g.kelly@gmail.com> - 2016-06-08 08:58 -0600

csiph-web