-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
gh-129915: Add __qualname__ to class namespace when constructing slotted dataclass
#129916
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?
Changes from 1 commit
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 |
|---|---|---|
|
|
@@ -3367,6 +3367,25 @@ class A: | |
| self.assertFalse(hasattr(A, "__slots__")) | ||
| self.assertTrue(hasattr(B, "__slots__")) | ||
|
|
||
| def test_slots_qualname(self): | ||
| # Test that __qualname__ is set correctly when using slots | ||
| @dataclass(slots=True) | ||
| class C: | ||
| x: int | ||
|
|
||
| def __init_subclass__(cls): | ||
| expected = f'TestSlots.test_slots_qualname.<locals>.{cls.__name__}' | ||
| self.assertEqual(cls.__qualname__, expected) | ||
|
|
||
| self.assertTrue('__qualname__' in C.__dict__) | ||
| self.assertEqual(C.__qualname__, 'TestSlots.test_slots_qualname.<locals>.C') | ||
|
|
||
| @dataclass(slots=True) | ||
| class D(C): | ||
| pass | ||
|
|
||
| self.assertEqual(D.__qualname__, 'TestSlots.test_slots_qualname.<locals>.D') | ||
|
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. Can you please run your tests as 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. Hmm I'm not following how running it directly would produce a different result than the passing CI check? What am I missing? 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 assume @sobolevn thinks the imported class name might 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, I am not sure it will, just double checking. |
||
|
|
||
| # Can't be local to test_frozen_pickle. | ||
| @dataclass(frozen=True, slots=True) | ||
| class FrozenSlotsClass: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.