Skip to content

Do not include annotations that are not part of named tuple fields#12951

Merged
Viicos merged 3 commits intopydantic:mainfrom
galuszkak:fix-named-tuples
Mar 23, 2026
Merged

Do not include annotations that are not part of named tuple fields#12951
Viicos merged 3 commits intopydantic:mainfrom
galuszkak:fix-named-tuples

Conversation

@galuszkak
Copy link
Copy Markdown
Contributor

@galuszkak galuszkak commented Mar 23, 2026

Change Summary

Fixed a TypeError during instantiation of NamedTuple subclasses by ensuring Pydantic only generates schema for fields defined in the base NamedTuple._fields attribute. This prevents extraneous annotations in subclasses from being incorrectly treated as valid constructor arguments, resolving issue #7987

Related issue number

fix #7987

Checklist

  • The pull request title is a good summary of the changes - it will be used in the changelog
  • Unit tests for the changes exist
  • Tests pass on CI
  • Documentation reflects the changes where applicable
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

@github-actions github-actions Bot added the relnotes-fix Used for bugfixes. label Mar 23, 2026
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Mar 23, 2026

Merging this PR will not alter performance

✅ 212 untouched benchmarks


Comparing galuszkak:fix-named-tuples (2186d75) with main (ebe2802)

Open in CodSpeed

@galuszkak
Copy link
Copy Markdown
Contributor Author

This is dependent on #12952 for now...

@github-actions
Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  pydantic/_internal
  _generate_schema.py 1540-1541
Project Total  

This report was generated by python-coverage-comment-action

Comment thread pydantic/_internal/_generate_schema.py Outdated
Comment thread tests/test_types_namedtuple.py Outdated
@Viicos Viicos added the deferred Deferred until future release or until something else gets done label Mar 23, 2026
@Viicos Viicos changed the title fix: NamedTuple inheritance with extra annotations - fixes #7987 Do not include annotations that are not part of named tuple fields Mar 23, 2026
@Viicos Viicos added relnotes-change Used for changes to existing functionality which don't have a better categorization. needs-blogpost-entry This PR needs to be documented in the release notes blog post and removed deferred Deferred until future release or until something else gets done labels Mar 23, 2026
@Viicos Viicos merged commit 0574aaa into pydantic:main Mar 23, 2026
81 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-blogpost-entry This PR needs to be documented in the release notes blog post relnotes-change Used for changes to existing functionality which don't have a better categorization. relnotes-fix Used for bugfixes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NamedTuple parameter resolution does not match constructor

2 participants