Batuhan Taskaya <[email protected]> added the comment:
> Hopefully Batuhan has a recollection of what I am thinking of, there was some
> significant delay while we figured out what to do about some of these.
The major one that I'd recall is that inspect.signature() just uses whatever is
in __annotations__ instead of resolving those. Now that __future__.annotations
is not the default one, we can add a new option named 'resolve_annotations' and
call typing.get_type_hints when activated. Here is a quick demo;
from __future__ import annotations
import inspect
def foo(a: int, b: int) -> str:
...
def _get_annotations(func, **signature_opts):
signature = inspect.signature(func, **signature_opts)
return {
param.name: param.annotation
for param in signature.parameters.values()
}
print('bare: ', _get_annotations(foo))
print('annotations resolved: ', _get_annotations(foo, resolve_annotations=True))
bare: {'a': 'int', 'b': 'int'}
annotations resolved: {'a': <class 'int'>, 'b': <class 'int'>}
This would be a clear feature for both PEP 563 users + people who are still
using string annotations mixed with normal ones. What do you think Guido?
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue38605>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com