[issue43006] Changed behaviour of inspect.signature() in Python 3.10
Zac Hatfield-Dodds
report at bugs.python.org
Sat Jan 23 01:24:23 EST 2021
New submission from Zac Hatfield-Dodds <zac.hatfield.dodds at gmail.com>:
Consider the following snippet, which passes on Python 3.9 and earlier:
import inspect
def f(x: int = None):
pass
print(inspect.signature(constructor))
assert inspect.signature(constructor).parameters["a"].annotation == int
But under Python 3.10 (alpha 4), the annotation is instead read as Optional[int]. This is correct for typing.get_type_hints(), but *not* for inspect.signature().
I therefore suspect that this is an accidental side-effect from support for PEP-563 deferred evaluation of annotations.
----------
components: Library (Lib)
messages: 385524
nosy: Zac Hatfield-Dodds
priority: normal
severity: normal
status: open
title: Changed behaviour of inspect.signature() in Python 3.10
versions: Python 3.10
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43006>
_______________________________________
More information about the Python-bugs-list
mailing list