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
[Regression] TypeVar crashes when name is specified via keyword parameters #110782
): if name is passed as a positional argument and there are no constraints, constraints is an empty tuple, but if it's a keyword argument, constraints is NULL.
I'll send a PR in a moment with a workaround in typevarobject.c.
Fix is merged, and will be in 3.12 soon; 3.12.1 should include the fix.
I'll note that using a keyword argument for the name of a TypeVar is not an officially supported part of the type system, so to make your code portable across type checkers and Python versions, you should use a positional argument for the name. It appears that pyright supports the keyword argument form, but mypy does not. We'll continue to support the keyword argument form at runtime for backwards compatibility.
I'm fine with whatever syntax works here, but ideally AC should support annotations on *args (e.g., I should be able to write *args: bool to get any number of bool args), and as Alex says it should error on unsupported constructs.
Activity
mxschmitt commentedon Oct 12, 2023
Investigation: Changing
TypeVar(name="Handler")toTypeVar("Handler")fixes it for me.JelleZijlstra commentedon Oct 12, 2023
This is possibly a bug in Argument Clinic (see
cpython/Objects/typevarobject.c
Line 326 in e733136
nameis passed as a positional argument and there are no constraints,constraintsis an empty tuple, but if it's a keyword argument,constraintsis NULL.I'll send a PR in a moment with a workaround in typevarobject.c.
pythongh-110782: Fix crash when TypeVar is constructed with keyword args
gh-110782: Fix crash when TypeVar is constructed with keyword args (#…
pythongh-110782: Fix crash when TypeVar is constructed with keyword a…
JelleZijlstra commentedon Oct 12, 2023
Fix is merged, and will be in 3.12 soon; 3.12.1 should include the fix.
I'll note that using a keyword argument for the name of a TypeVar is not an officially supported part of the type system, so to make your code portable across type checkers and Python versions, you should use a positional argument for the name. It appears that pyright supports the keyword argument form, but mypy does not. We'll continue to support the keyword argument form at runtime for backwards compatibility.
[3.12] gh-110782: Fix crash when TypeVar is constructed with keyword …
sobolevn commentedon Oct 14, 2023
Thanks!
@JelleZijlstra would you accept
cpython/Objects/typevarobject.c
Lines 329 to 330 in e733136
to be changed to just
?
Because this seems like a fortunate event that this notation works. I was not able to find that this is a documented approach.
If so, I would send a PR :)
AlexWaygood commentedon Oct 14, 2023
We should try to make sure AC raises an error if it encounters syntax like this which isn't supported! Cc. @erlend-aasland
sobolevn commentedon Oct 14, 2023
Ok, will do after #110864
JelleZijlstra commentedon Oct 14, 2023
Thanks @sobolevn for investigating further!
I'm fine with whatever syntax works here, but ideally AC should support annotations on
*args(e.g., I should be able to write*args: boolto get any number of bool args), and as Alex says it should error on unsupported constructs.pythongh-110782: Fix crash when TypeVar is constructed with keyword a…