crates/ty_python_semantic/resources/mdtest/generics/builtins.md
In typeshed, list inherits clear from MutableSequence, and dict inherits it from
MutableMapping. We can call these methods through list and dict without supplying type
arguments.
def clear_containers(items: list[int], mapping: dict[str, int]) -> None:
list.clear(items)
dict.clear(mapping)
dictWhen we define dict in a custom typeshed, we must take care to define it as a generic class in the
same way as in the real typeshed.
[environment]
typeshed = "/typeshed"
/typeshed/stdlib/builtins.pyi:
class object: ...
class int: ...
class tuple: ...
class dict[K, V, Extra]: ...
/typeshed/stdlib/typing_extensions.pyi:
def reveal_type(obj, /): ...
If we don't, then we may get "surprising" results when inferring the types of variadic keyword arguments.
def f(**kwargs):
reveal_type(kwargs) # revealed: dict[Unknown, Unknown, Unknown]
def g(**kwargs: int):
reveal_type(kwargs) # revealed: dict[Unknown, Unknown, Unknown]