diff --git a/crates/ty_python_semantic/resources/mdtest/generics/pep695/classes.md b/crates/ty_python_semantic/resources/mdtest/generics/pep695/classes.md index 56cdbc426b..92840bcf1a 100644 --- a/crates/ty_python_semantic/resources/mdtest/generics/pep695/classes.md +++ b/crates/ty_python_semantic/resources/mdtest/generics/pep695/classes.md @@ -630,5 +630,34 @@ class C[T](C): ... class D[T](D[int]): ... ``` +## Tuple as a PEP-695 generic class + +Our special handling for `tuple` does not break if `tuple` is defined as a PEP-695 generic class in +typeshed: + +```toml +[environment] +python-version = "3.12" +typeshed = "/typeshed" +``` + +`/typeshed/stdlib/builtins.pyi`: + +```pyi +class tuple[T]: ... +``` + +`/typeshed/stdlib/typing_extensions.pyi`: + +```pyi +def reveal_type(obj, /): ... +``` + +`main.py`: + +```py +reveal_type((1, 2, 3)) # revealed: tuple[Literal[1], Literal[2], Literal[3]] +``` + [crtp]: https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern [f-bound]: https://en.wikipedia.org/wiki/Bounded_quantification#F-bounded_quantification diff --git a/crates/ty_python_semantic/resources/mdtest/narrow/type.md b/crates/ty_python_semantic/resources/mdtest/narrow/type.md index ef754d021a..fccd6e54fa 100644 --- a/crates/ty_python_semantic/resources/mdtest/narrow/type.md +++ b/crates/ty_python_semantic/resources/mdtest/narrow/type.md @@ -223,6 +223,17 @@ def _[T](x: A | B): reveal_type(x) # revealed: A[int] | B ``` +## Narrowing for tuple + +An early version of caused us to crash on this: + +```py +def _(val): + if type(val) is tuple: + # TODO: better would be `Unknown & tuple[object, ...]` + reveal_type(val) # revealed: Unknown & tuple[Unknown, ...] +``` + ## Limitations ```py