New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Regression] TypeVar crashes when name is specified via keyword parameters #110782
Comments
Investigation: Changing |
This is possibly a bug in Argument Clinic (see cpython/Objects/typevarobject.c Line 326 in e733136
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. |
…rgs (pythonGH-110784) (cherry picked from commit d2a536b) Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
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. |
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 :) |
We should try to make sure AC raises an error if it encounters syntax like this which isn't supported! Cc. @erlend-aasland |
Ok, will do after #110864 |
Thanks @sobolevn for investigating further! I'm fine with whatever syntax works here, but ideally AC should support annotations on |
Crash report
What happened?
Good: 3.11.X
Bad: 3.12.0
Downstream issue: jfhbrook/pyee#134
CPython versions tested on:
3.12
Operating systems tested on:
Linux, macOS
Output from running 'python -VV' on the command line:
Python 3.12.0 (main, Oct 12 2023, 00:42:11) [GCC 12.2.0]
Linked PRs
The text was updated successfully, but these errors were encountered: