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


Groups > comp.lang.python > #109680

Re: Recursive type annotations

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Ian Kelly <ian.g.kelly@gmail.com>
Newsgroups comp.lang.python
Subject Re: Recursive type annotations
Date Wed, 8 Jun 2016 08:58:22 -0600
Lines 22
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>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
X-Trace news.uni-berlin.de TF6jLzrFjgF4Guu9mPf6iAcw9OlKbr9wmWkcmeZW03qA==
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.032
X-Spam-Evidence '*H*': 0.94; '*S*': 0.00; 'static': 0.03; 'nameerror:': 0.09; 'received:209.85.218': 0.10; 'def': 0.13; 'wed,': 0.15; '2016': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:type': 0.16; 'wrote:': 0.16; 'string': 0.17; 'typing': 0.18; '>>>': 0.20; 'fix': 0.21; 'pass': 0.22; 'am,': 0.23; 'defined': 0.23; 'references': 0.23; 'written': 0.24; 'header:In-Reply-To:1': 0.24; 'module': 0.25; 'right.': 0.27; 'message-id:@mail.gmail.com': 0.27; 'module.': 0.27; 'specifically': 0.28; 'pep': 0.29; 'class': 0.33; 'url:python': 0.33; 'covered': 0.34; 'received:google.com': 0.35; 'follows:': 0.35; 'but': 0.36; 'url:org': 0.36; 'received:209.85': 0.36; 'url:library': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'received:209': 0.38; 'anything': 0.38; 'url:en': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'url:3': 0.60; 'documents': 0.61; 'forward': 0.66; 'covers': 0.72; "'test'": 0.84; 'checker': 0.84; 'nagy': 0.84; 'to:name:python': 0.84; 'url:readthedocs': 0.84; 'url:latest': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-transfer-encoding; bh=22+gAWMUkX6e54i3MejprHJFv6t2ikqoh/VPJBquvN4=; b=SC+CWzbYqOqVyHAdDsda+yyPyPg0mXnM95irTC0GYrmbCWX77KMPZj9kdmvWONueyg kw8lD1kYX4i+ZNYeV3oUTjezirVqfUiPK+6CYcjP0nWOlqPloSNbmiysF2CVF6HhJanX dO4uN8+i7PAK5RTedxnSHukXZxXLN24Cdl+aTSFLf2smicSb/tSJUe8wicNdZiBtdHce fn3/L82DEITY9vmV4GGoJxfzDxkute6M0P6xbBOPkCXc9ZJL4GOfhqnyzU3AMcM5co57 LqXk1h6kRq/uUaz6yLKlpxcQicg990yK77S1U8pkbSEIGQt2O/m49hfdfjPjfiL5zuIl yRMw==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-transfer-encoding; bh=22+gAWMUkX6e54i3MejprHJFv6t2ikqoh/VPJBquvN4=; b=fNj6hmxKvOrvQs+d5jcYhq3nTUMtV/7MIaAQUN5ZzF0n6uNtuNNdv3fyldnWN0zNrV HuTm3AihJzlnbRtjUy3fPrSZR4DBT/XxQ0xtUdYMvffYYq5aWtkgieQHaL9eaoHF5dMl kCOpJdhwlhFXm4JFsbKC+MHH6tLITw/tzqWPMEhJe/1vv/VUfxwMW2nsbz+NzKb298tp F++3BuBWlTkt++AoDvTdrG8hv+Il/kG3fs7KvCrA2uReg6A+E4DaTzABLsQIp1EJIBXU D807PHwQOa9RtoOg7kFdCGbN48BUTYgmPbQV7mXPB7/qzHVyGUXHTOtDCofDhHFxgWtz VCcA==
X-Gm-Message-State ALyK8tLqvDxkPxXnLvozzPJOsYT1CqHROpJ8bsExSFLsgj/dtHbOeYHvvKCml7l14LroGdLrpWDDqAzCNs/XWw==
X-Received by 10.157.48.36 with SMTP id d33mr3314493otc.30.1465397942065; Wed, 08 Jun 2016 07:59:02 -0700 (PDT)
In-Reply-To <7de91f01-4b8c-8f29-294a-4f2f6909bc89@shopzeus.com>
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 <CALwzid=AJDKFZG=j7Lw3EqGdnWkNiEUuP2Ceuo7xT_c8ybd-1A@mail.gmail.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> <7de91f01-4b8c-8f29-294a-4f2f6909bc89@shopzeus.com>
Xref csiph.com comp.lang.python:109680

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