-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
gh-130870 Fix _eval_type Handling for GenericAlias with Unflattened Arguments and Union Types #130897
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
base: main
Are you sure you want to change the base?
gh-130870 Fix _eval_type Handling for GenericAlias with Unflattened Arguments and Union Types #130897
Changes from 5 commits
b38f689
bea2a10
d6ea064
3af57b4
d3a633c
b85d920
b0db6a6
596b6f5
37b760c
aeb602b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Type: Bugfix | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is too much text; we don't need the "type" and "title" (we get that from the linked issue number). We don't have to mention that the tests pass: if they didn't, we wouldn't merge the change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, this is screaming AI-generated to me, as well as the PR description. @sharktide, it's OK to use AI for some cases, but please refer to the devguide for the rules on using LLMs to generate PRs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was running out of time as I was at school and I had a short break so I asked chatgpt to make the news entry and pr desc. The first few lines of the news entry I basically copied from my previous prs as I don’t have much experience There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I’ll change it when I get a chance There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No worries, feel free to ask us for help or clarification on the process. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed it to this Issue: :gh:`130870`
Detailed changes:
This change improves the handling of ``GenericAlias`` and ``Union`` types in ``_eval_type``, ensuring that callable arguments for ``GenericAlias`` are unflattened and that ``Union`` types are properly evaluated. |
||
Title: Fix ``_eval_type`` Handling for ``GenericAlias`` with Unflattened Arguments and ``Union`` Types | ||
Issue: :gh:`130870` | ||
|
||
Detailed changes: | ||
This change improves the handling of ``GenericAlias`` and ``Union`` types in ``_eval_type``, ensuring that callable arguments for ``GenericAlias`` are unflattened and that ``Union`` types are properly evaluated. It resolves complex annotations, including recursive and generic types. All relevant tests, including those for forward references, generics, ``Union`` types, and recursion, passed successfully without any issues. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the motivation for calling
_should_unflatten_callable_args
here?Please add tests demonstrating the new behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why call _should_unflatten_callable_args:
_should_unflatten_callable_args is used to make sure that the arguments of a callable type are handled properlt sometimes, the arguments are grouped together like in a list and need to be unpacked into separate arguments. I'll link a modified version of the test script here and then also link the results
*Sorry my capitalization sucks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I made a mistake. The appropriate example should be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is my test script:
And result:
Note: The DeprecationWarning is a problem with my test script rather than the modified function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test cases should go in
test_typing.py
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JelleZijlstra Done added class TestGenericAliasHandling to test_typing.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JelleZijlstra Ready for review