Ken Jin <kenjin4...@gmail.com> added the comment:
> 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. Spot on about PEP 563 becoming the default being the culprit! The what's new for Python 3.10 states that inspect.signature will try to resolve types https://docs.python.org/3.10/whatsnew/3.10.html#pep-563-postponed-evaluation-of-annotations-becomes-default. For annotations, inspect.signature internally calls get_type_hints: https://github.com/python/cpython/blob/master/Lib/inspect.py#L2194 A simple solution I can think of is to add a flag to get_type_hints to disable converting to Optional[int] for inspect.signature. I nosied some people involved in issue38605 so that they can give their opinions on this. ---------- nosy: +BTaskaya, gvanrossum, kj _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue43006> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com