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


Groups > comp.lang.python > #109678

Re: Recursive type annotations

From Nagy László Zsolt <gandalf@shopzeus.com>
Newsgroups comp.lang.python
Subject Re: Recursive type annotations
Date 2016-06-08 15:31 +0200
Message-ID <mailman.79.1465392677.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>

Show all headers | View raw


>>         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

Back to comp.lang.python | Previous | NextPrevious in thread | Next 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