Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Being against torture ought to be sort of a bipartisan thing." -- Karl Lehenbauer


devel / comp.lang.python / Re: return type same as class gives NameError.

SubjectAuthor
o Re: return type same as class gives NameError.dn

1
Re: return type same as class gives NameError.

<mailman.29.1697993726.3828.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=24168&group=comp.lang.python#24168

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: PythonL...@DancesWithMice.info (dn)
Newsgroups: comp.lang.python
Subject: Re: return type same as class gives NameError.
Date: Mon, 23 Oct 2023 05:54:50 +1300
Organization: DWM
Lines: 43
Message-ID: <mailman.29.1697993726.3828.python-list@python.org>
References: <c95f85e1-1524-49ac-aed5-18eaea4cedac@vub.be>
<c2e0292a-8ff6-4cb0-af09-93c2f43cb4ea@DancesWithMice.info>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de irL7glVeYibEu2+4JexcyQGNCeHdbtbRmD45ZiUYuCPw==
Cancel-Lock: sha1:4Q9ohU6l6q2b1a+qgQ+gODPF4+M= sha256:TrujTVMDd4Cxg2HFLOytWNBVZlj2JUL/cQo11BWnqgU=
Return-Path: <PythonList@DancesWithMice.info>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=danceswithmice.info header.i=@danceswithmice.info
header.b=bIkJWhwv; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'def': 0.04; 'traceback':
0.04; '(most': 0.05; 'last):': 0.05; '=dn': 0.09; 'float': 0.09;
'from:addr:danceswithmice.info': 0.09; 'from:addr:pythonlist':
0.09; 'insist': 0.09; 'module:': 0.09; 'received:192.168.1.64':
0.09; 'subject:class': 0.09; 'url:stable': 0.09; 'import': 0.15;
'(because': 0.16; 'antoon': 0.16; 'declare': 0.16; 'defined.':
0.16; 'mean:': 0.16; 'message-id:@DancesWithMice.info': 0.16;
'pardon': 0.16; 'received:cloud': 0.16; 'received:rangi.cloud':
0.16; 'skip:\xc2 70': 0.16; 'typing': 0.16; 'wrote:': 0.16;
'to:addr:python-list': 0.20; 'skip:_ 10': 0.22; 'it,': 0.29;
'header:User-Agent:1': 0.30; 'header:Organization:1': 0.31; '"",':
0.32; 'python-list': 0.32; 'received:192.168.1': 0.32; 'but':
0.32; 'someone': 0.34; 'header:In-Reply-To:1': 0.34; 'url-
ip:104.17/16': 0.35; 'following': 0.35; 'using': 0.37; 'class':
0.37; 'received:192.168': 0.37; 'file': 0.38; 'this,': 0.39;
'use': 0.39; 'explain': 0.40; '10,': 0.61; 'skip:\xc2 10': 0.62;
'sequence': 0.69; '8bit%:100': 0.76; 'happens': 0.84; 'skip:" 40':
0.84; 'subject:type': 0.91; 'union': 0.91
DKIM-Filter: OpenDKIM Filter v2.11.0 vps.rangi.cloud D141E47AA
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=danceswithmice.info;
s=staff; t=1697993696;
bh=UMYgkMp1xUvvgG7QlnvQ9xDEyvtr7BWWPIHo8T/VvXc=;
h=Date:Subject:To:References:From:In-Reply-To:From;
b=bIkJWhwvaz+x9gvg5P26WvOSKi2trTmZ/rPet8bkW85xQlo6i4gXiEg9y77e3CiMO
pY59VfbuClRwNF+gS8eN2tVzuLqxbpIl3wxLSpnSl33WFArpQkCzK/hWcGxxPnasvs
4t7XZ6vj7DRKWHlu2H8N3rc78eNJrbArooFzaoEXm2Aej0D5/ktS0qAY57lus3AIoy
nKySHAJvKeG3Z0uMI6QzeEoc0q0+q4uxC2VX1nsFDWMJ2+dkRlZZIjqEYGvqnafDoQ
q6JDcz36gRTMqrVPfYjtpsPjV6Z7WNJsTQ5Sql7NqSprAk8Qzq3Mh1WLrhUxdxaOKE
NPk1eZPwx1SWA==
User-Agent: Mozilla Thunderbird
Content-Language: en-GB
In-Reply-To: <c95f85e1-1524-49ac-aed5-18eaea4cedac@vub.be>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
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: <https://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: <c2e0292a-8ff6-4cb0-af09-93c2f43cb4ea@DancesWithMice.info>
X-Mailman-Original-References: <c95f85e1-1524-49ac-aed5-18eaea4cedac@vub.be>
 by: dn - Sun, 22 Oct 2023 16:54 UTC

On 23/10/2023 04.50, Antoon Pardon via Python-list wrote:
> I have the following small module:
>
> =-=-=-=-=-=-=-=-=-=-=-= 8< =-=-=-=-=-=-=-=-=-=-=-=-=
>
> from typing import NamedTuple, TypeAlias, Union
> from collections.abc import Sequence
>
> PNT: TypeAlias = tuple[float, float]
>
> class Pnt (NamedTuple):
>     x: float
>     y: float
>
>     def __add__(self, other: PNT) -> Pnt:
>         return Pnt(self[0] + other[0], self[1] + other[1])
>
> =-=-=-=-=-=-=-=-=-=-=-= >8 =-=-=-=-=-=-=-=-=-=-=-=-=
>
> But when I import this, I get the following diagnostic:
>
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "/home/sisc/projecten/iudex/problem.py", line 10, in <module>
>     class Pnt (NamedTuple):
>   File "/home/sisc/projecten/iudex/problem.py", line 14, in Pnt
>     def __add__(self, other: PNT) -> Pnt:
>                                      ^^^
> NameError: name 'Pnt' is not defined. Did you mean: 'PNT'?
>
>
> Can someone explain what I am doing wrong?

What happens when the advice is followed?

Not sure why declare type-alias and then don't use it, but if insist on
using class-name will be making a "forward-reference" (because class has
not yet been fully defined) - see
https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html#forward-references

--
Regards,
=dn

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor