Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-116241: Add support of multiple inheritance with typing.NamedTuple#31781
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?
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
939d5f064f0c5fd4bc7113159b219d48f8729dd4b7File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -8003,7 +8003,40 @@ class X(NamedTuple): | ||
| def test_multiple_inheritance(self): | ||
| class A: | ||
| pass | ||
| @property | ||
| def x(self): | ||
| return 4 | ||
| @property | ||
| def y(self): | ||
| return 5 | ||
| def __len__(self): | ||
| return 10 | ||
| class X(NamedTuple, A): | ||
| x: int | ||
| self.assertEqual(X.__bases__, (tuple, A)) | ||
| self.assertEqual(X.__orig_bases__, (NamedTuple, A)) | ||
| self.assertEqual(X.__mro__, (X, tuple, A, object)) | ||
| a = X(3) | ||
| self.assertEqual(a.x, 3) | ||
| self.assertEqual(a.y, 5) | ||
| self.assertEqual(len(a), 1) | ||
| class Y(A, NamedTuple): | ||
Member 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. Maybe add a test to check the order of the members as well when doing unpacking? And maybe test | ||
| x: int | ||
| self.assertEqual(Y.__bases__, (A, tuple)) | ||
| self.assertEqual(Y.__orig_bases__, (A, NamedTuple)) | ||
| self.assertEqual(Y.__mro__, (Y, A, tuple, object)) | ||
| a = Y(3) | ||
| self.assertEqual(a.x, 3) | ||
| self.assertEqual(a.y, 5) | ||
| self.assertEqual(len(a), 10) | ||
| def test_multiple_inheritance_errors(self): | ||
| class A(NamedTuple): | ||
| x: int | ||
| with self.assertRaises(TypeError): | ||
| class X(NamedTuple, A): | ||
| x: int | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add support for arbitrary multiple inheritance with :class:`typing.NamedTuple`. |
Uh oh!
There was an error while loading. Please reload this page.
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 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.
+1