[New-bugs-announce] [issue45857] Type hint for methods

洪明聖 report at bugs.python.org
Sun Nov 21 09:48:31 EST 2021


New submission from 洪明聖 <hung11112002 at gmail.com>:

The class methods have a problem compiling when the type refers to the union of itself and others.


# tmp.py
class Foo:
    def __init__(self, tmp: "Foo"|int):
        pass


# Error
Traceback (most recent call last):
  File "/Project/Mslc/Grammar/tmp.py", line 1, in <module>
    class Foo:
  File "/Project/Mslc/Grammar/tmp.py", line 2, in Foo
    def __init__(self, tmp: "Foo"|int):
TypeError: unsupported operand type(s) for |: 'str' and 'type'

----------
messages: 406720
nosy: TNThung
priority: normal
severity: normal
status: open
title: Type hint for methods
type: compile error
versions: Python 3.10

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


More information about the New-bugs-announce mailing list