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


Groups > comp.lang.python > #109678

Re: Recursive type annotations

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Nagy László Zsolt <gandalf@shopzeus.com>
Newsgroups comp.lang.python
Subject Re: Recursive type annotations
Date Wed, 8 Jun 2016 15:31:18 +0200
Lines 17
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>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de IYEjvvs4xYpEm1Vl/fnS2wvHlJXW7byDWT/iWYDI7K0A==
Return-Path <gandalf@shopzeus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.035
X-Spam-Evidence '*H*': 0.93; '*S*': 0.00; 'nameerror:': 0.09; 'def': 0.13; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:type': 0.16; 'string': 0.17; 'fix': 0.21; 'pass': 0.22; 'defined': 0.23; 'written': 0.24; 'header:In-Reply-To:1': 0.24; 'right.': 0.27; 'pep': 0.29; 'class': 0.33; 'url:python': 0.33; 'thanks!': 0.34; 'follows:': 0.35; 'but': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'to:addr:python.org': 0.40; 'url:3': 0.60; "'test'": 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=shopzeus.com; s=shopzeus_com; t=1465392676; bh=cptT3Ic3dIXYw/mU0CXvrDvbB5Q6TnXlEmwJ6u6DGn4=; h=Subject:To:References:From:Date:In-Reply-To:From; b=MumAvVUeaJke11GIfxCER5quXyM11wgYvH9b6zTlF5JYXzhml8zZ01ZoJWtpmaa0b EnOZPIvFe7nAOkf+QeOP5VsEUNIlKKHxa6iuSlEtSOlfKO0HWgYy6bty/qAcXqifJ9 9tFJYY2Et5ebVGwWdle19xNe/N6QmRzTDHd5MYOKe6kQut3FSa9mabSnSOyKJPQdGi wDOUmzFi/8klh7eszSe1cfgBhyzqpi81p0GipXQkMIV+EhPvm1enrSLqJAGZmkbHc+ ewuvhhWfeCkj/XXyTyFb04OlosNv5954jl9eFcMAUErtdNZ86sl/efcuftQbsLYnYH qlGeLTEybmRaA==
In-Reply-To <slrnnlg6bs.6f8.jon+usenet@sable.unequivocal.co.uk>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <7de91f01-4b8c-8f29-294a-4f2f6909bc89@shopzeus.com>
X-Mailman-Original-References <8e439d4f-182d-334d-ffbe-8c39856cdd33@shopzeus.com> <mailman.77.1465390948.2306.python-list@python.org> <slrnnlg6bs.6f8.jon+usenet@sable.unequivocal.co.uk>
Xref csiph.com comp.lang.python:109678

Show key headers only | 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