[New-bugs-announce] [issue46807] Wrong class __annotations__ when field name and type are equal

Konstantin report at bugs.python.org
Sun Feb 20 08:05:31 EST 2022


New submission from Konstantin <dev at kgubaev.org>:

In [18]: class Str(str):
    ...:     pass

In [19]: class Class:
    ...:     Str: str
    ...: 
    ...: 
    ...: Class.__annotations__
Out[19]: {'Str': str}

In [20]: class Class:
    ...:     Str: str = ""
    ...: 
    ...: 
    ...: Class.__annotations__
Out[20]: {'Str': str}

In [21]: class Class:
    ...:     Str: Str = ""
    ...: 
    ...: 
    ...: Class.__annotations__      # Wrong!
Out[21]: {'Str': ''}

In [22]: class Class:
    ...:     Str: Str
    ...: 
    ...: 
    ...: Class.__annotations__
Out[22]: {'Str': __main__.Str}

It reproduced all the version which support annotations as part of the core (I tested python 3.6..3.10.2)

----------
components: Parser
messages: 413586
nosy: kgubaev, lys.nikolaou, pablogsal
priority: normal
severity: normal
status: open
title: Wrong class __annotations__ when field name and type are equal
type: behavior
versions: Python 3.10

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46807>
_______________________________________


More information about the New-bugs-announce mailing list