Message391732
> 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? |
|
Date |
User |
Action |
Args |
2021-04-23 20:35:29 | BTaskaya | set | recipients:
+ BTaskaya, gvanrossum, barry, brett.cannon, terry.reedy, vstinner, eric.smith, methane, lukasz.langa, serhiy.storchaka, levkivskyi, pablogsal, miss-islington, gousaiyang |
2021-04-23 20:35:29 | BTaskaya | set | messageid: <1619210129.53.0.547573692203.issue38605@roundup.psfhosted.org> |
2021-04-23 20:35:29 | BTaskaya | link | issue38605 messages |
2021-04-23 20:35:29 | BTaskaya | create | |
|