[ Web Proxy ]
URL:
Viewing: https://github-redirect.dependabot.com/python/cpython/pull/31779 [Back]  [Original]

bpo-43923: Allow NamedTuple multiple inheritance by juliusgeo Pull Request #31779 python/cpython GitHub
Skip to content

Navigation Menu

Sign in

Repository navigation

More items

bpo-43923: Allow NamedTuple multiple inheritance - #31779

Closed
juliusgeo wants to merge 10 commits into
python:mainfrom
juliusgeo:bpo43923-2
Closed

juliusgeo wants to merge 10 commits into
python:mainfrom
juliusgeo:bpo43923-2

Conversation

@juliusgeo [@juliusgeo]

@juliusgeo [@juliusgeo] juliusgeo commented Mar 9, 2022 •
edited by bedevere-bot
Loading

Copy link
Copy Markdown
[Go]

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.

[Hide comment]

This looks like it's still mostly a revert, which I don't think is the right approach since it ends up losing a bunch of past improvements. Try to make the minimal change necessary to make things work.

[Go]
Comment thread Lib/typing.py Outdated
def _make_nmtuple(name, types):
msg = "NamedTuple('Name', [(f0, t0), (f1, t1), ...]); each t must be a type"
types = [(n, _type_check(t, msg)) for n, t in types]
nm_tpl = collections.namedtuple(name, [n for n, t in types])

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.

[Hide comment]

collections.namedtuple now supports default= directly, so we should use that

[Go]
Comment thread Lib/typing.py Outdated
defaults=defaults, module=module)
nm_tpl.__annotations__ = nm_tpl.__new__.__annotations__ = types
def _make_nmtuple(name, types):
msg = "NamedTuple('Name', [(f0, t0), (f1, t1), ...]); each t must be a type"

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.

[Hide comment]

You're missing the improved error message from the existing code

[Go]
Comment thread Lib/typing.py Outdated
default_names=', '.join(defaults_dict.keys())))
nm_tpl.__new__.__annotations__ = dict(types)
nm_tpl.__new__.__defaults__ = tuple(defaults)
nm_tpl._field_defaults = defaults_dict

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.

[Hide comment]

No need to restore this old attribute

[Go]

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

[Go]

JelleZijlstra commented Mar 10, 2022 •
edited
Loading

Copy link
Copy Markdown
Member

Note there's an alternative PR from Serhiy: #31781.

[Go]

Copy link
Copy Markdown
Member

Note there's an alternative PR from Serhiy: #31781.

I still like Serhiy's more. In particular, I think it's best to keep NamedTuple a function, rather than a class. Given what inheriting from NamedTuple actually does (dynamically create a new tuple subclass), I think it makes much more sense for it to be a function.

[Go]

Copy link
Copy Markdown
Member

We merged #92027 to allow generic namedtuples. I don't think we want more general multiple inheritance. Thanks for your PR though!

[Go]
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

Footer

© 2026 GitHub, Inc.

Web Proxy Viewer  |  New URL  |  Original Page