[ty] Emit diagnostics for invalid dynamic namedtuple fields#22575
Merged
charliermarsh merged 1 commit intomainfrom Jan 14, 2026
Merged
[ty] Emit diagnostics for invalid dynamic namedtuple fields#22575charliermarsh merged 1 commit intomainfrom
charliermarsh merged 1 commit intomainfrom
Conversation
Diagnostic diff on typing conformance testsChanges were detected when running ty on typing conformance tests--- old-output.txt 2026-01-14 18:39:50.447232489 +0000
+++ new-output.txt 2026-01-14 18:39:50.759234420 +0000
@@ -762,6 +762,10 @@
namedtuples_define_functional.py:37:21: error[too-many-positional-arguments] Too many positional arguments: expected 3, got 4
namedtuples_define_functional.py:42:18: error[invalid-argument-type] Argument is incorrect: Expected `int`, found `Literal["1"]`
namedtuples_define_functional.py:43:15: error[invalid-argument-type] Argument is incorrect: Expected `int`, found `float`
+namedtuples_define_functional.py:52:25: error[invalid-named-tuple] Duplicate field name `a` in `namedtuple()`: Field `a` already defined; will raise `ValueError` at runtime
+namedtuples_define_functional.py:53:25: error[invalid-named-tuple] Field name `def` in `namedtuple()` cannot be a Python keyword: Will raise `ValueError` at runtime
+namedtuples_define_functional.py:54:25: error[invalid-named-tuple] Field name `def` in `namedtuple()` cannot be a Python keyword: Will raise `ValueError` at runtime
+namedtuples_define_functional.py:55:25: error[invalid-named-tuple] Field name `_d` in `namedtuple()` cannot start with an underscore: Will raise `ValueError` at runtime
namedtuples_define_functional.py:69:1: error[missing-argument] No argument provided for required parameter `a`
namedtuples_type_compat.py:22:23: error[invalid-assignment] Object of type `Point` is not assignable to `tuple[int, int]`
namedtuples_type_compat.py:23:28: error[invalid-assignment] Object of type `Point` is not assignable to `tuple[int, str, str]`
@@ -1049,4 +1053,4 @@
typeddicts_usage.py:28:17: error[missing-typed-dict-key] Missing required key 'name' in TypedDict `Movie` constructor
typeddicts_usage.py:28:18: error[invalid-key] Unknown key "title" for TypedDict `Movie`: Unknown key "title"
typeddicts_usage.py:40:24: error[invalid-type-form] The special form `typing.TypedDict` is not allowed in type expressions
-Found 1051 diagnostics
+Found 1055 diagnostics
|
|
MichaReiser
reviewed
Jan 14, 2026
Comment on lines
6829
to
6830
| if seen_names.contains(name_str) { | ||
| if let Some(builder) = |
Member
There was a problem hiding this comment.
Looks like claude still doesn't know how to do let chains 😅
MichaReiser
reviewed
Jan 14, 2026
| let name_str = field_name.as_str(); | ||
|
|
||
| // Check for duplicate field names. | ||
| if seen_names.contains(name_str) { |
Member
There was a problem hiding this comment.
I think you can use seen_names.insert(name_str) here. This adds the name if it doesn't exist yet and otherwise does nothing.
I'd also be somewhat inclined to not build the hash set and instead use a window iterating over field_names to see if the same name appears anywhere later in field_names. Unless we assume that field_names is very large, in which case we want to avoid the O(n^2) search
MichaReiser
reviewed
Jan 14, 2026
MichaReiser
reviewed
Jan 14, 2026
Comment on lines
6904
to
6908
| if defaults_count > num_fields { | ||
| if let Some(defaults_kw) = defaults_kw { | ||
| if let Some(builder) = | ||
| self.context.report_lint(&INVALID_NAMED_TUPLE, defaults_kw) | ||
| { |
Member
Author
|
(Will mark for review once upstream merges + rebased + addressed Micha's initial comments.) |
f354f24 to
9563206
Compare
04c1323 to
9333d35
Compare
AlexWaygood
approved these changes
Jan 14, 2026
9563206 to
c390952
Compare
9333d35 to
1bfdfaf
Compare
1bfdfaf to
81fe244
Compare
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Removes some TODOs from the dynamic namedtuple implementation.