Skip to content

Conversation

@AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood commented Aug 16, 2025

Summary

This fails at runtime:

from typing import NamedTuple

class Foo(NamedTuple, object): ...

and the typing spec mandates that we should detect that, but we currently don't. This PR adds a new lint for detecting this mistake.

Test Plan

Mdtest/snapshots

@AlexWaygood AlexWaygood added the ty Multi-file analysis & type inference label Aug 16, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Aug 16, 2025

Diagnostic diff on typing conformance tests

Changes were detected when running ty on typing conformance tests
--- old-output.txt	2025-08-18 12:00:59.100097702 +0000
+++ new-output.txt	2025-08-18 12:01:01.560109174 +0000
@@ -672,6 +672,7 @@
 namedtuples_define_class.py:95:1: error[type-assertion-failure] Argument does not have asserted type `int | float`
 namedtuples_define_class.py:96:1: error[type-assertion-failure] Argument does not have asserted type `int | float`
 namedtuples_define_class.py:98:19: error[invalid-argument-type] Argument is incorrect: Expected `str`, found `float`
+namedtuples_define_class.py:105:24: error[invalid-named-tuple] NamedTuple class `Unit` cannot use multiple inheritance except with `Generic[]`
 namedtuples_type_compat.py:22:1: error[invalid-assignment] Object of type `Point` is not assignable to `tuple[int, int]`
 namedtuples_type_compat.py:23:1: error[invalid-assignment] Object of type `Point` is not assignable to `tuple[int, str, str]`
 namedtuples_usage.py:34:7: error[index-out-of-bounds] Index 3 is out of bounds for tuple `Point` with length 3
@@ -860,5 +861,5 @@
 typeddicts_operations.py:60:1: error[type-assertion-failure] Argument does not have asserted type `str | None`
 typeddicts_type_consistency.py:101:1: error[invalid-assignment] Object of type `Unknown | None` is not assignable to `str`
 typeddicts_usage.py:40:24: error[invalid-type-form] The special form `typing.TypedDict` is not allowed in type expressions. Did you mean to use a concrete TypedDict or `collections.abc.Mapping[str, object]` instead?
-Found 861 diagnostics
+Found 862 diagnostics
 WARN A fatal error occurred while checking some files. Not all project files were analyzed. See the diagnostics list above for details.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 16, 2025

mypy_primer results

No ecosystem changes detected ✅
No memory usage changes detected ✅

@AlexWaygood
Copy link
Member Author

(The new typing conformance suite diagnostic is correct!)

Copy link
Contributor

@sharkdp sharkdp left a comment

Choose a reason for hiding this comment

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

Nice — thank you.

AlexWaygood and others added 2 commits August 18, 2025 12:52
Co-authored-by: David Peter <sharkdp@users.noreply.github.com>
@AlexWaygood AlexWaygood enabled auto-merge (squash) August 18, 2025 11:59
@AlexWaygood AlexWaygood merged commit fbf24be into main Aug 18, 2025
36 of 37 checks passed
@AlexWaygood AlexWaygood deleted the alex/namedtuple-multiple-inheritance branch August 18, 2025 12:03
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.

3 participants