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 — gh-89687: fix `get_type_hints` with dataclasses `__init__` generation by sobolevn · Pull Request #29158 · python/cpython Conversation
|
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Bikeshedding point, but: would it be better to put these tests in test_dataclasses? For the similar issue with TypedDict, the new tests were put next to the other TypedDict tests. Moreover, given that this is a very specific issue with the way that the dataclasses module generates __init__ functions, it seems like more of a dataclasses bug than a get_type_hints bug.
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.
I'm fine with any decision from maintainers 👍
Both cases make sense.
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.
Agreed!
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.
|
I found a corner case: when I define a proxy module, say from __future__ import annotations import dataclasses from test import dataclass_textanno # We need to be sure that `Foo` is not in scope class Custom: pass @dataclasses.dataclass class Child(dataclass_textanno.Bar): custom: Custom @dataclasses.dataclass(init=False) class WithFutureInit(Child): def __init__(self, foo: dataclass_textanno.Foo, custom: Custom) -> None: pass Then, this test does not pass: def test_dataclass_from_proxy_module(self): from test import dataclass_textanno, dataclass_textanno2 from dataclasses import dataclass @dataclass class Default(dataclass_textanno2.Child): pass self.assertEqual( get_type_hints(Defualt.__init__), {'foo': dataclass_textanno.Foo, 'custom': dataclass_textanno2.Custom, 'return': type(None)}, ) Output: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Now it is even more wild. I collect |
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.
|
One more case: same names obviously get overriden by the current logic. I will try something else. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Not sure I understand. What's a failing test case? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@AlexWaygood done! Here's the failing test case: https://github.com/python/cpython/pull/29158/files#diff-f0436842533448f8f02a19081d7c9cc8372b6685756caf32c83dfecebbee68e7R3189-R3219 And here's my new solution: https://github.com/python/cpython/pull/29158/files#diff-44ce2dc1c4922b2f5cf7631d8f86cc569a4c25eb003aaecdc2bc22eb9163d5f5R455-R468 I now manually resolve |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Ahh, I understand -- thanks! |
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.
There was an error while loading. Please reload this page.
|
Thanks! Done 👍 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This PR is stale because it has been open for 30 days with no activity. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Co-authored-by: Alex Waygood <[email protected]>
Co-authored-by: Alex Waygood <[email protected]>
Co-authored-by: Alex Waygood <[email protected]>
7205490 to
df5fda9
Compare
|
Rebased 🙂 Friendly ping to @ericvsmith and @Fidget-Spinner |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I'm putting this off until the SC makes a decision on PEP 649. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
get_type_hints with dataclasses __init__ generationget_type_hints with dataclasses __init__ generation
|
PEP 649 is accepted and implemented in 3.14, so what should be done with this PR? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I lost context of this, please recreate :) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
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.