GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — bpo-46333: Honor `module` parameter in ForwardRef by aha79 · Pull Request #30536 · python/cpython Conversation
|
|
Since this is your first contribution, you should also feel free to add your name to https://github.com/python/cpython/blob/main/Misc/ACKS (this is entirely optional, only if you'd like to). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@Fidget-Spinner I hope you can review and merge this PR? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
@gvanrossum Sure. Leave it to me. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Great work! We're almost ready to merge, I just have some minor concerns.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| fr = typing.ForwardRef('int') | ||
| self.assertEqual(fr, typing.ForwardRef('int')) | ||
| self.assertNotEqual(List['int'], List[int]) | ||
| self.assertNotEqual(fr, typing.ForwardRef('int', module=__name__)) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I wonder if this test is run directly, will __name__ be `main``? Wouldn't that make the test pass incorrectly? (Throwing this question out there because I'm not too sure myself). Maybe we should be safe and give it a distinct name?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The test is to ensure that ForwardRef with module set is different from ForwardRef with module not set (That was previsously not the case). The actual value of module (or __name__) is not relevant. Under the hood the comparison is None vs str
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
My bad, thanks for pointing that out. I mistakenly assumed it would grab a default value from the current scope to populate module in things like ClassVar['int'] due to the _type_check/_type_convert function (I'm now shocked that it doesn't and only does that for TypedDict).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yes, unfortunately the current module is not captured automatically.
The current scope/module is typicallly obtained by get_type_hints because a class knows its module (and so all ForwardRefs in member annotations can be correctly resolved. But each forward Ref does originally not know its module).
However for type aliases this does not work, and there one needs the explicit module.
For example
Json = Union[ List['Json'], Dict[str,'Json'], int, float, bool, None ]
cannot be exported (and expect to work) unless one sets the module for each forward ref.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Co-authored-by: Ken Jin <[email protected]>
|
@Fidget-Spinner, do you see this one as more of a bugfix that should be backported, or more of an enhancement/behaviour change? (This is just for my clarification, @aha79 — I'm fairly new to the triage team 🙂) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
@AlexWaygood this is a grey area. On one hand, generally, anything dealing with However, this specific I'm inclined to accept the PR without the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Thanks, that's really clarifying! It might be worth noting that @sobolevn proposes in #29158 (not yet merged) to use the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Btw @aha79 — could I ask if you've signed the CLA? For legal reasons, it may be difficult for CPython to merge a PR from you if you haven't 🙂 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Yes, sorry. I completely understand that. I clarify with my organization (This will be ok, but may take a few more days) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Of course! No rush :) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
@AlexWaygood The CLA is now signed. Sorry that it took a while. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Thanks, no worries!
To me it makes sense to split off the Fidget-Spinner is currently on a break from open source — @JelleZijlstra, if you've got the time, do you have any thoughts on this PR? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Co-authored-by: Alex Waygood <[email protected]>
There were already tests for |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sorry, I think I was unclear — my bad :) We now have two test methods for testing cpython/Lib/test/test_typing.py Line 2648 in 9dd2f8f
Could you move the new tests for |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
I didn't mean to imply otherwise! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Sorry I misunderstood. I move/adapted the tests to the right place |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Feel free to open a new PR for the __repr__ changes (you can link to the same BPO issue).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@gvanrossum could we possibly get the full test suite run on this PR, please? :) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@AlexWaygood / @JelleZijlstra Is this ready to merge? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Looks that way to me :) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Yes I think it's good. It can wait though, hopefully I can merge it myself next week :) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @aha79 for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
The `module` parameter carries semantic information about the forward ref. Forward refs are different if they refer to different module even if they have the same name. This affects the `__eq__`, `__repr__` and `__hash__` methods. Co-authored-by: Andreas Hangauer <[email protected]> Co-authored-by: Alex Waygood <[email protected]> Co-authored-by: Ken Jin <[email protected]> (cherry picked from commit 6e7b813) Co-authored-by: aha79 <[email protected]>
|
GH-31379 is a backport of this pull request to the 3.10 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
The `module` parameter carries semantic information about the forward ref. Forward refs are different if they refer to different module even if they have the same name. This affects the `__eq__`, `__repr__` and `__hash__` methods. Co-authored-by: Andreas Hangauer <[email protected]> Co-authored-by: Alex Waygood <[email protected]> Co-authored-by: Ken Jin <[email protected]> (cherry picked from commit 6e7b813) Co-authored-by: aha79 <[email protected]>
|
GH-31380 is a backport of this pull request to the 3.9 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…H-31379) The `module` parameter carries semantic information about the forward ref. Forward refs are different if they refer to different module even if they have the same name. This affects the `__eq__`, `__repr__` and `__hash__` methods. Co-authored-by: Andreas Hangauer <[email protected]> Co-authored-by: Alex Waygood <[email protected]> Co-authored-by: Ken Jin <[email protected]> (cherry picked from commit 6e7b813) Co-authored-by: aha79 <[email protected]> Automerge-Triggered-By: GH:JelleZijlstra
The `module` parameter carries semantic information about the forward ref. Forward refs are different if they refer to different module even if they have the same name. This affects the `__eq__`, `__repr__` and `__hash__` methods. Co-authored-by: Andreas Hangauer <[email protected]> Co-authored-by: Alex Waygood <[email protected]> Co-authored-by: Ken Jin <[email protected]> (cherry picked from commit 6e7b813) Co-authored-by: aha79 <[email protected]>
The `module` parameter carries semantic information about the forward ref. Forward refs are different if they refer to different module even if they have the same name. This affects the `__eq__`, `__repr__` and `__hash__` methods. Co-authored-by: Andreas Hangauer <[email protected]> Co-authored-by: Alex Waygood <[email protected]> Co-authored-by: Ken Jin <[email protected]> (cherry picked from commit 6e7b813) Co-authored-by: aha79 <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.