Message388756
Ah, I wasn't aware of that, thanks for the pointer! So what inspect does internally is:
def _get_type_hints(func, **kwargs):
try:
return typing.get_type_hints(func, **kwargs)
except Exception:
# First, try to use the get_type_hints to resolve
# annotations. But for keeping the behavior intact
# if there was a problem with that (like the namespace
# can't resolve some annotation) continue to use
# string annotations
return func.__annotations__
Which means there's even some "prior art" there already falling back to a string when the annotation couldn't be resolved. Doing so in typing.get_type_hints on a per-argument basis would thus also make inspect more consistent:
Right now,
print(repr(inspect.signature(fun).parameters['b'].annotation))
in my example returns a string, but when changing the annotation for `a`, the returned annotation for `b` is now magically a `typing.Union` object.
(I personally would indeed expect inspect to resolve those annotations, but yeah, let's keep that in issue43355.) |
|
Date |
User |
Action |
Args |
2021-03-15 18:29:53 | The Compiler | set | recipients:
+ The Compiler, gvanrossum, eric.smith, levkivskyi, kj |
2021-03-15 18:29:53 | The Compiler | set | messageid: <1615832993.8.0.0417125720427.issue43463@roundup.psfhosted.org> |
2021-03-15 18:29:53 | The Compiler | link | issue43463 messages |
2021-03-15 18:29:53 | The Compiler | create | |
|