-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
bpo-46581: Propagate private vars via _GenericAlias.copy_with #31061
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
bpo-46581: Propagate private vars via _GenericAlias.copy_with #31061
Conversation
ebe8d33
to
ae11f6f
Compare
90d730e
to
ae11f6f
Compare
|
ae11f6f
to
4efbc2c
Compare
4efbc2c
to
7b9a6ff
Compare
Requested [here](python#31061 (comment)).
7b9a6ff
to
9510c95
Compare
) (cherry picked from commit 2031149) Co-authored-by: Matt Bogosian <[email protected]>
) (cherry picked from commit 2031149) Co-authored-by: Matt Bogosian <[email protected]>
(cherry picked from commit 2031149) Co-authored-by: Matt Bogosian <[email protected]>
(cherry picked from commit 2031149) Co-authored-by: Matt Bogosian <[email protected]>
ba8b094
to
c9def58
Compare
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.
There is more straightforward way to fix a conflict.
- Add
_typevar_types=(TypeVar, ParamSpec), _paramspec_tvars=True
to the call of_ConcatenateGenericAlias
in_Concatenate
. - Remove
_ConcatenateGenericAlias.__initt__
. - Remove a special case from
_GenericAlias.copy_with
.
Also please move changes in comments and docstrings to enother PR. They distract.
Misc/NEWS.d/next/Library/2022-02-01-11-32-47.bpo-46581.t7Zw65.rst
Outdated
Show resolved
Hide resolved
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
72b9e76
to
6bf1f6c
Compare
6bf1f6c
to
6db57f5
Compare
Lib/test/test_typing.py
Outdated
original = Callable[P, int] | ||
self.assertEqual(original.__parameters__, (P,)) | ||
copied = original[P] | ||
self.assertEqual(original.__parameters__, copied.__parameters__) |
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.
Could you add some more complicated test cases? Ideas:
- The original has a
Concatenate[int, P]
in it (original = Callable[Concatenate[int, P], int]; original[P].__paramaters__ == (P,)
) - Instead of substituting a
P
in, substitute in aConcatenate
or something like[int, T]
, and then theT
should be in__parameters__
.
P2 = ParamSpec('P2') | ||
C1 = Callable[P, int] | ||
self.assertEqual(C1.__parameters__, (P,)) | ||
self.assertEqual(C1[P2].__parameters__, (P2,)) |
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.
Only this test was failed.
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.
Thank you for pulling through @posita . This was a pretty tricky PR.
Thanks @posita for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10. |
Sorry, @posita and @serhiy-storchaka, I could not cleanly backport this to |
Should I work on resolving this? |
Yes please :) Let me know if you need any help. |
I would love a nudge on where to learn how to do this manually. (I'm unfamiliar with the process.) Is it as simple as resolving any conflicts against the 3.10 branch and then submitting a PR or is there more involved? |
Yup. Submit a PR against the 3.10 and/or 3.9 branch after resolving conflicts. The bot is a little off. An easier way without installing things is to use the The other even easier alternative if you're using GitHub desktop, is to drag and drop the commit from the left panel from main into your new branch that is based off 3.10/3.9. The app will then warn you about conflicts, and you can resolve them in a code editor (this means accepting/rejecting changes or overwriting them altogether manually). |
…ythonGH-31061) (Cherry-picked from 32bf359.) pythonGH-26091 added the _typevar_types and _paramspec_tvars instance variables to _GenericAlias. However, they were not propagated consistently. This commit addresses the most prominent deficiency identified in bpo-46581 (namely their absence from _GenericAlias.copy_with), but there could be others. Co-authored-by: Ken Jin <[email protected]> Co-authored-by: Serhiy Storchaka <[email protected]>
GH-31821 is a backport of this pull request to the 3.10 branch. |
Thanks @Fidget-Spinner! Cherry-picking is all good. I just didn't know if there was other repo- or CI-specific magical incantations I needed to invoke or procedures I needed to follow. Question (maybe for @JelleZijlstra): This is marked as needed a back-port to 3.10, but not to 3.9. Should this also be back-ported to 3.9? |
…H-31061) (GH-31821) (Cherry-picked from 32bf359.) GH-26091 added the _typevar_types and _paramspec_tvars instance variables to _GenericAlias. However, they were not propagated consistently. This commit addresses the most prominent deficiency identified in bpo-46581 (namely their absence from _GenericAlias.copy_with), but there could be others. Co-authored-by: Ken Jin <[email protected]> Co-authored-by: Serhiy Storchaka <[email protected]> Co-authored-by: Ken Jin <[email protected]> Co-authored-by: Serhiy Storchaka <[email protected]>
@posita re backporting to 3.9, we don't need it as pre-3.10 ParamSpec didn't exist so we never needed these parameters then. Anyways, congrats on becoming a CPython contributor! |
Oh, right! Duh. Thanks all! I very much appreciate all the hand-holding. |
) (cherry picked from commit 2031149) Co-authored-by: Matt Bogosian <[email protected]>
GH-26091 added the
_typevar_types
and_paramspec_tvars
instance variables to_GenericAlias
. However, they were not propagated consistently. This commit addresses the most prominent deficiency identified in bpo-46581 (namely their absence from_GenericAlias.copy_with
), but there could be others.https://bugs.python.org/issue46581