diff --git a/crates/ty_python_semantic/resources/mdtest/named_tuple.md b/crates/ty_python_semantic/resources/mdtest/named_tuple.md index db3aab7bfd404a..52016c76b8647a 100644 --- a/crates/ty_python_semantic/resources/mdtest/named_tuple.md +++ b/crates/ty_python_semantic/resources/mdtest/named_tuple.md @@ -37,6 +37,10 @@ Person(3, "Eve", 99, "extra") # error: [invalid-argument-type] Person(id="3", name="Eve") + +# TODO: over-writing NamedTuple fields should be an error +alice.id = 42 +bob.age = None ``` Alternative functional syntax: @@ -52,6 +56,19 @@ reveal_type(alice2.id) # revealed: @Todo(GenericAlias instance) reveal_type(alice2.name) # revealed: @Todo(GenericAlias instance) ``` +### Definition + +TODO: Fields without default values should come before fields with. + +```py +from typing import NamedTuple + +class Location(NamedTuple): + altitude: float = 0.0 + latitude: float # this should be an error + longitude: float +``` + ### Multiple Inheritance Multiple inheritance is not supported for `NamedTuple` classes: @@ -89,6 +106,20 @@ reveal_type(alice.level) # revealed: int alice = SuperUser(1, "Alice", 3) ``` +TODO: If any fields added by the subclass conflict with those in the base class, that should be +flagged. + +```py +from typing import NamedTuple + +class User(NamedTuple): + id: int + name: str + +class SuperUser(User): + id: int # this should be an error +``` + ### Generic named tuples ```toml