You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
typing.get_type_hints() works for Callable[[], None] from the typing module, but not collections.abc #91621
typing.get_type_hints() works for Callable[[], None] from the typing module, but not collections.abc. This is the standard way to annotate a callable which takes no arguments, and the generic types from typing should behave identically to those in collections.abc.
CPython 3.11.0a7 (and I believe back to a3), found via CI for Hypothesis, and reproduced in Ubuntu/WSL2 locally. I'm skipping that test for now, and will re-enable when this is fixed.
We do this kind of thing a couple times in typing.py, I can open a PR:
diff --git a/Lib/typing.py b/Lib/typing.py
index 3e0fbdb989..af424c2109 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -350,7 +350,11 @@ def _eval_type(t, globalns, localns, recursive_guard=frozenset()):
ForwardRef(arg) if isinstance(arg, str) else arg
for arg in t.__args__
)
- t = t.__origin__[args]
+ if (t.__origin__ is collections.abc.Callable
+ and not (len(args) == 2 and _is_param_expr(args[0]))):
+ t = t.__origin__[(args[:-1], args[-1])]
+ else:
+ t = t.__origin__[args]
ev_args = tuple(_eval_type(a, globalns, localns, recursive_guard) for a in t.__args__)
if ev_args == t.__args__:
return t
We do this kind of thing a couple times in typing.py, I can open a PR:
🤦 . Seeing this again, I'm sad that the special case has to exist. Unfortunately, this seems like an easy way to trip up new contributors. Please open a PR.
Activity
AlexWaygood commentedon Apr 16, 2022
Reproduced, and I agree that this looks like a regression in 3.11. On 3.10:
On 3.11:
hauntsaninja commentedon Apr 17, 2022
Looks like this is a result of #30900 cc @NiklasRosenstein @JelleZijlstra
hauntsaninja commentedon Apr 17, 2022
The complexity here traces back to some of the decisions made in https://bugs.python.org/issue42195
We do this kind of thing a couple times in typing.py, I can open a PR:
Fidget-Spinner commentedon Apr 17, 2022
🤦 . Seeing this again, I'm sad that the special case has to exist. Unfortunately, this seems like an easy way to trip up new contributors. Please open a PR.
pythongh-91621: Fix typing.get_type_hints for collections.abc.Callable
gh-91621: Fix typing.get_type_hints for collections.abc.Callable (#91656
JelleZijlstra commentedon May 2, 2022
Thanks @Zac-HD for the pre-beta testing and @hauntsaninja for the patch!