Skip to content

Comments

[ty] Emit invalid-named-tuple on namedtuple classes that have field names starting with underscores#21697

Merged
AlexWaygood merged 1 commit intomainfrom
alex/private-namedtuple-field
Dec 1, 2025
Merged

[ty] Emit invalid-named-tuple on namedtuple classes that have field names starting with underscores#21697
AlexWaygood merged 1 commit intomainfrom
alex/private-namedtuple-field

Conversation

@AlexWaygood
Copy link
Member

Summary

This raises TypeError at runtime and is caught by all other major type checkers

Test Plan

snapshot/mdtest

@AlexWaygood AlexWaygood added the ty Multi-file analysis & type inference label Nov 29, 2025
@astral-sh-bot
Copy link

astral-sh-bot bot commented Nov 29, 2025

Diagnostic diff on typing conformance tests

Changes were detected when running ty on typing conformance tests
--- old-output.txt	2025-12-01 11:33:22.595865886 +0000
+++ new-output.txt	2025-12-01 11:33:26.305906382 +0000
@@ -752,6 +752,7 @@
 namedtuples_define_class.py:48:22: error[too-many-positional-arguments] Too many positional arguments: expected 4, got 5
 namedtuples_define_class.py:49:23: error[unknown-argument] Argument `other` does not match any known parameter
 namedtuples_define_class.py:69:20: error[too-many-positional-arguments] Too many positional arguments: expected 3, got 4
+namedtuples_define_class.py:76:5: error[invalid-named-tuple] NamedTuple field `_y` cannot start with an underscore
 namedtuples_define_class.py:86:5: error[invalid-named-tuple] NamedTuple field without default value cannot follow field(s) with default value(s): Field `latitude` defined here without a default value
 namedtuples_define_class.py:121:1: error[type-assertion-failure] Type `Property[int | float]` does not match asserted type `Property[float]`
 namedtuples_define_class.py:122:1: error[type-assertion-failure] Type `int | float` does not match asserted type `float`
@@ -1039,4 +1040,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 1041 diagnostics
+Found 1042 diagnostics

@AlexWaygood
Copy link
Member Author

The new typing-conformance diagnostic is a true positive.

@AlexWaygood AlexWaygood changed the title [ty] Emit invalid-namedtuple on namedtuple classes that have field names starting with leading underscrores [ty] Emit invalid-namedtuple on namedtuple classes that have field names starting with leading underscores Nov 29, 2025
@AlexWaygood AlexWaygood changed the title [ty] Emit invalid-namedtuple on namedtuple classes that have field names starting with leading underscores [ty] Emit invalid-namedtuple on namedtuple classes that have field names starting with underscores Nov 29, 2025
@AlexWaygood AlexWaygood changed the title [ty] Emit invalid-namedtuple on namedtuple classes that have field names starting with underscores [ty] Emit invalid-named-tuple on namedtuple classes that have field names starting with underscores Nov 29, 2025
@astral-sh-bot
Copy link

astral-sh-bot bot commented Nov 29, 2025

mypy_primer results

Changes were detected when running on open source projects
scikit-build-core (https://github.com/scikit-build/scikit-build-core)
+ src/scikit_build_core/build/_pathutil.py:25:38: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `str | PathLike[str]`, found `DirEntry[Path]`
+ src/scikit_build_core/build/_pathutil.py:27:24: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `str | PathLike[str]`, found `DirEntry[Path]`
+ src/scikit_build_core/build/wheel.py:98:20: error[no-matching-overload] No overload of bound method `__init__` matches arguments
- Found 41 diagnostics
+ Found 44 diagnostics

No memory usage changes detected ✅

@AlexWaygood
Copy link
Member Author

The changes reported by mypy_primer are all unrelated (astral-sh/ty#1670)

@AlexWaygood AlexWaygood force-pushed the alex/private-namedtuple-field branch from 3972bd2 to 71ab5fc Compare December 1, 2025 11:31
@AlexWaygood AlexWaygood enabled auto-merge (squash) December 1, 2025 11:32
@AlexWaygood AlexWaygood merged commit a2096ee into main Dec 1, 2025
40 checks passed
@AlexWaygood AlexWaygood deleted the alex/private-namedtuple-field branch December 1, 2025 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants