FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-116241: Add support of multiple inheritance with typing.NamedTuple by serhiy-storchaka · Pull Request #31781 · python/cpython · GitHub

Repository navigation

gh-116241: Add support of multiple inheritance with typing.NamedTuple - #31781

Draft
serhiy-storchaka wants to merge 8 commits into
python:mainfrom
serhiy-storchaka:typing-namedtuple-multiple-inheritance
Draft

serhiy-storchaka wants to merge 8 commits into
python:mainfrom
serhiy-storchaka:typing-namedtuple-multiple-inheritance

Conversation

serhiy-storchaka commented Mar 9, 2022 •
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

serhiy-storchaka force-pushed the typing-namedtuple-multiple-inheritance branch from 637bdd3 to 64f0c5f Compare April 28, 2022 16:48
serhiy-storchaka marked this pull request as ready for review April 28, 2022 17:18

JelleZijlstra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think this goes too far because it's not realistic to expect type checkers to support arbitrary base classes on NamedTuple. Also, there haven't been any user requests that I can see for multiple inheritance with anything other than Generic. So I'd prefer to merge the other PR that allows multiple inheritance with Generic only.

Copy link
Copy Markdown
Member

I think this goes too far because it's not realistic to expect type checkers to support arbitrary base classes on NamedTuple. Also, there haven't been any user requests that I can see for multiple inheritance with anything other than Generic. So I'd prefer to merge the other PR that allows multiple inheritance with Generic only.

I also think it makes sense to only allow multiple inheritance with Generic, for now. It's a smaller change; and, there should be opportunity to rethink it in the future if it turns out that people really need arbitrary multiple inheritance for whatever reason.

Copy link
Copy Markdown
Member

So, let's just close this?

serhiy-storchaka changed the title bpo-43923: Add support of multiple inheritance with typing.NamedTuple gh-116241: Add support of multiple inheritance with typing.NamedTuple Mar 2, 2024
serhiy-storchaka force-pushed the typing-namedtuple-multiple-inheritance branch from 5077333 to d4bc711 Compare March 2, 2024 16:09

Jason-Y-Z left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

people really need arbitrary multiple inheritance for whatever reason

Thanks for reopening! This looks like the case now indeed

CoolCat467 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Looks great! I ended up doing nearly exactly the same thing in some code of my own to get around this limitation.

Fidget-Spinner removed their request for review October 9, 2024 14:36
Comment thread Doc/library/typing.rst Outdated
Comment thread Doc/whatsnew/3.13.rst Outdated
Comment thread Doc/library/typing.rst Outdated

Copy link
Copy Markdown
Member Author

Thank you @AlexWaygood and @gvanrossum. Updated to 3.14 and applied the suggestions.

AlexWaygood left a comment •
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Given that we've had multiple requests for this, I'm okay with landing it. But please get sign-offs from @gvanrossum and @JelleZijlstra before merging.

gvanrossum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Let's do it! (I approve of the idea, I haven't carefully reviewed the code.)

JelleZijlstra self-requested a review October 9, 2024 18:41

Copy link
Copy Markdown
Member

I'm OK with this given the discussion on the issue; will take another look at the code soon.

hugovk commented Apr 23, 2025

Copy link
Copy Markdown
Member

Reminder for this: the 3.14 beta freeze is in two weeks.

picnixz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

That'd be great to have. I needed this more than once!

Comment thread Doc/library/typing.rst Outdated
disallowed in Python 3.15. To create a NamedTuple class with 0 fields,
use ``class NT(NamedTuple): pass`` or ``NT = NamedTuple("NT", [])``.

.. versionchanged:: 3.14

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Suggested change
.. versionchanged:: 3.14
.. versionchanged:: next

Comment thread Lib/test/test_typing.py
self.assertEqual(a.y, 5)
self.assertEqual(len(a), 1)

class Y(A, NamedTuple):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Maybe add a test to check the order of the members as well when doing unpacking? And maybe test class Z(X, Y, NamedTuple)? (I don't know if this leads to a MRO incompatibilty though)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

It will be error. This is tested in the next test.

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 10, 2026
johnslavik self-requested a review April 10, 2026 15:05
Comment thread Lib/typing.py
Comment on lines -3019 to -3022
for base in bases:
if base is not _NamedTuple and base is not Generic:
raise TypeError(
'can only inherit from a NamedTuple type and Generic')

johnslavik Apr 10, 2026 •
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

johnslavik removed the stale Stale PR or inactive for long period of time. label Apr 13, 2026
serhiy-storchaka marked this pull request as draft April 13, 2026 17:58

Copy link
Copy Markdown

This PR is stale because it has been open for 90 days with no activity.

github-actions Bot added the stale Stale PR or inactive for long period of time. label Jul 12, 2026

Copy link
Copy Markdown
Contributor

Any progress?

github-actions Bot removed the stale Stale PR or inactive for long period of time. label Jul 18, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 90 days with no activity.

github-actions Bot added the stale Stale PR or inactive for long period of time. label Oct 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Stale PR or inactive for long period of time. topic-typing type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.


Back | FazBrowse Home | New Git URL