diff --git a/packages/pyright-internal/src/tests/samples/setComprehension1.py b/packages/pyright-internal/src/tests/samples/comprehension10.py similarity index 85% rename from packages/pyright-internal/src/tests/samples/setComprehension1.py rename to packages/pyright-internal/src/tests/samples/comprehension10.py index 189631f86558..dc0c69ec25f2 100644 --- a/packages/pyright-internal/src/tests/samples/setComprehension1.py +++ b/packages/pyright-internal/src/tests/samples/comprehension10.py @@ -1,6 +1,6 @@ # This sample tests type checking for set comprehensions. -from typing import Generator, Set +from typing import Generator a = [1, 2, 3, 4] @@ -10,12 +10,12 @@ def func1() -> Generator[int, None, None]: return b -def func2() -> Set[int]: +def func2() -> set[int]: c = {elem for elem in a} return c -def func3() -> Set[str]: +def func3() -> set[str]: c = {elem for elem in a} # This should generate an error because diff --git a/packages/pyright-internal/src/tests/samples/protocol1.py b/packages/pyright-internal/src/tests/samples/protocol1.py index 3cef5a67dfed..fbb93c4103a7 100644 --- a/packages/pyright-internal/src/tests/samples/protocol1.py +++ b/packages/pyright-internal/src/tests/samples/protocol1.py @@ -1,6 +1,6 @@ # This sample tests the type checker's handling of generic protocol types. -from typing import Generic, List, Optional, TypeVar, Protocol +from typing import Generic, TypeVar, Protocol T = TypeVar("T") T_co = TypeVar("T_co", covariant=True) @@ -73,16 +73,16 @@ class NotProto2: # This should generate an error because "Protocol" cannot be used # as a type argument. -var2: List[Protocol] = [] +var2: list[Protocol] = [] class Abstract1(Protocol[T_contra]): - def do(self, x: Optional[T_contra]): + def do(self, x: T_contra | None): ... class Concrete1: - def do(self, x: Optional[int]): + def do(self, x: int | None): pass diff --git a/packages/pyright-internal/src/tests/samples/protocol13.py b/packages/pyright-internal/src/tests/samples/protocol13.py index 744e073ae184..e7f011358d72 100644 --- a/packages/pyright-internal/src/tests/samples/protocol13.py +++ b/packages/pyright-internal/src/tests/samples/protocol13.py @@ -2,21 +2,16 @@ # include named-only parameters that match to positional parameters # within class that is being tested for protocol compatibility. -from typing import Optional, Protocol +from typing import Protocol class CollectionProtocol(Protocol): - def watch( - self, - *, - max_time: Optional[int] = ..., - key: Optional[str] = ..., - ) -> None: + def watch(self, *, max_time: int | None = ..., key: str | None = ...) -> None: ... class Collection: - def watch(self, key: Optional[str] = None, max_time: Optional[int] = None) -> None: + def watch(self, key: str | None = None, max_time: int | None = None) -> None: ... diff --git a/packages/pyright-internal/src/tests/samples/protocol17.py b/packages/pyright-internal/src/tests/samples/protocol17.py index f0b977f79835..e18936697038 100644 --- a/packages/pyright-internal/src/tests/samples/protocol17.py +++ b/packages/pyright-internal/src/tests/samples/protocol17.py @@ -1,6 +1,6 @@ # This sample tests for generic protocol variance consistency. -from typing import Protocol, TypeVar, Union +from typing import Protocol, TypeVar from typing_extensions import ParamSpec # pyright: strict @@ -13,7 +13,7 @@ class Protocol1(Protocol[_T1, _T2, _T3]): - def m1(self, p0: _T1, p1: _T2, p2: _T3) -> Union[_T1, _T2]: + def m1(self, p0: _T1, p1: _T2, p2: _T3) -> _T1 | _T2: ... def m2(self) -> _T1: @@ -93,6 +93,7 @@ class Protocol9(Protocol[_T1_co]): def prop1(self) -> _T1_co: ... + class Protocol10(Protocol[_T1_co]): def m1(self) -> type[_T1_co]: ... diff --git a/packages/pyright-internal/src/tests/samples/protocol2.py b/packages/pyright-internal/src/tests/samples/protocol2.py index c5b51a7d64eb..657323af4124 100644 --- a/packages/pyright-internal/src/tests/samples/protocol2.py +++ b/packages/pyright-internal/src/tests/samples/protocol2.py @@ -2,7 +2,7 @@ # generic protocols with invariant, constrained, and contravariant # type arguments. -from typing import Optional, TypeVar, Protocol +from typing import TypeVar, Protocol T = TypeVar("T") @@ -24,11 +24,11 @@ def f(writer: Writer[bytes]): pass -def g(writer: Writer[T], v: Optional[T] = None): +def g(writer: Writer[T], v: T | None = None): pass -def h(writer: Writer[StrLike], v: Optional[StrLike] = None): +def h(writer: Writer[StrLike], v: StrLike | None = None): pass diff --git a/packages/pyright-internal/src/tests/samples/protocol20.py b/packages/pyright-internal/src/tests/samples/protocol20.py index c78b0eb085f0..59b6ecec581e 100644 --- a/packages/pyright-internal/src/tests/samples/protocol20.py +++ b/packages/pyright-internal/src/tests/samples/protocol20.py @@ -1,7 +1,7 @@ # This sample tests the case where a TypeVar is bound to a # protocol class. -from typing import Protocol, Type, TypeVar +from typing import Protocol, TypeVar class ClsProtocol(Protocol): @@ -14,7 +14,7 @@ def __init__(self): class Sample: @classmethod - def test(cls: Type[T1]) -> T1: + def test(cls: type[T1]) -> T1: return cls() diff --git a/packages/pyright-internal/src/tests/samples/protocol21.py b/packages/pyright-internal/src/tests/samples/protocol21.py index a850fa0efe3a..c899a9010dec 100644 --- a/packages/pyright-internal/src/tests/samples/protocol21.py +++ b/packages/pyright-internal/src/tests/samples/protocol21.py @@ -2,7 +2,7 @@ # to indicate a read-only attribute. It also tests that a member access through # a protocol class (not an instance) is flagged as an error. -from typing import Protocol, Type +from typing import Protocol class A(Protocol): @@ -15,7 +15,7 @@ class B: name: str -def do_something(a: A, class_a: Type[A]) -> None: +def do_something(a: A, class_a: type[A]) -> None: val1 = a.name reveal_type(val1, expected_text="str") diff --git a/packages/pyright-internal/src/tests/samples/protocol22.py b/packages/pyright-internal/src/tests/samples/protocol22.py index 591b8f9570c5..623354876c8a 100644 --- a/packages/pyright-internal/src/tests/samples/protocol22.py +++ b/packages/pyright-internal/src/tests/samples/protocol22.py @@ -2,7 +2,7 @@ # of multiple type variables is treated as covariant with the # union type, thus affecting the variance restriction. -from typing import Protocol, Tuple, TypeVar, Union +from typing import Protocol, TypeVar # pyright: strict @@ -18,26 +18,26 @@ # This is right, as `_T1_co` and `_T2_co` are only covariant with # return type. class P1(Protocol[_T1_co, _T2_co]): - def m1(self) -> Union[_T1_co, _T2_co]: + def m1(self) -> _T1_co | _T2_co: ... # This is right, as `_T1_contra` and `_T2_contra` are only covariant # with the argument type. class P2(Protocol[_T1_contra, _T2_contra]): - def m1(self, a: Union[_T1_contra, _T2_contra]) -> None: + def m1(self, a: _T1_contra | _T2_contra) -> None: ... # This is right, as `_T1` and `_T2` are both covariant with the # argument type and the return type. class P3(Protocol[_T1, _T2]): - def m1(self, a: _T1, b: _T2) -> Union[_T1, _T2]: + def m1(self, a: _T1, b: _T2) -> _T1 | _T2: ... # This is right, as `_T1` and `_T2` are both covariant with the # argument type and the return type. class P4(Protocol[_T1, _T2]): - def m2(self, a: Union[_T1, _T2]) -> Tuple[_T1, _T2]: + def m2(self, a: _T1 | _T2) -> tuple[_T1, _T2]: ... diff --git a/packages/pyright-internal/src/tests/samples/protocol23.py b/packages/pyright-internal/src/tests/samples/protocol23.py index 20aecc8d8f11..56a3576e2597 100644 --- a/packages/pyright-internal/src/tests/samples/protocol23.py +++ b/packages/pyright-internal/src/tests/samples/protocol23.py @@ -2,7 +2,7 @@ # can't be assigned to Type[Proto]. from abc import abstractmethod -from typing import Protocol, Type +from typing import Protocol class Proto(Protocol): @@ -16,7 +16,7 @@ def meth(self) -> int: return 42 -def func1(cls: Type[Proto]) -> int: +def func1(cls: type[Proto]) -> int: return cls().meth() @@ -26,7 +26,7 @@ def func1(cls: Type[Proto]) -> int: # not a concrete class type that implements the protocol. func1(Proto) -val1: Type[Proto] +val1: type[Proto] val1 = Concrete val1().meth() @@ -34,7 +34,7 @@ def func1(cls: Type[Proto]) -> int: val1 = Proto -def func2() -> Type[Proto]: +def func2() -> type[Proto]: ... diff --git a/packages/pyright-internal/src/tests/samples/protocol26.py b/packages/pyright-internal/src/tests/samples/protocol26.py index 3d1b8f6732fe..0a7793daf08f 100644 --- a/packages/pyright-internal/src/tests/samples/protocol26.py +++ b/packages/pyright-internal/src/tests/samples/protocol26.py @@ -1,8 +1,7 @@ # This sample tests protocol class assignment in a case that involves tricky # recursion. -from __future__ import annotations -from typing import Protocol, Sequence, TypeVar, Union, overload +from typing import Protocol, Sequence, TypeVar, overload _T_co = TypeVar("_T_co", covariant=True) @@ -18,23 +17,23 @@ def __getitem__(self, __x: SupportsIndex) -> _T_co: ... @overload - def __getitem__(self, __x: slice) -> TupleLike[_T_co]: + def __getitem__(self, __x: slice) -> "TupleLike[_T_co]": ... - def __getitem__(self, __x: slice | SupportsIndex) -> _T_co | TupleLike[_T_co]: + def __getitem__(self, __x: slice | SupportsIndex) -> "_T_co | TupleLike[_T_co]": ... class NestedSequence(Protocol[_T_co]): @overload - def __getitem__(self, index: int, /) -> _T_co | NestedSequence[_T_co]: + def __getitem__(self, index: int, /) -> "_T_co | NestedSequence[_T_co]": ... @overload - def __getitem__(self, index: slice, /) -> NestedSequence[_T_co]: + def __getitem__(self, index: slice, /) -> "NestedSequence[_T_co]": ... def func(t: TupleLike[int]): - x: Union[int, NestedSequence[int]] = t + x: int | NestedSequence[int] = t y: NestedSequence[int] = t diff --git a/packages/pyright-internal/src/tests/samples/protocol28.py b/packages/pyright-internal/src/tests/samples/protocol28.py index 06386436e0a2..948fa52b0234 100644 --- a/packages/pyright-internal/src/tests/samples/protocol28.py +++ b/packages/pyright-internal/src/tests/samples/protocol28.py @@ -1,32 +1,33 @@ # This sample tests a complicated use case involving multiple # callback protocols. -from typing import Callable, Protocol, TypeVar, Any +from typing import Protocol, TypeVar, Any _T1 = TypeVar("_T1", contravariant=True) _T2 = TypeVar("_T2", covariant=True) _T3 = TypeVar("_T3", covariant=True) -Tv_my_callable = TypeVar("Tv_my_callable", bound="MyCallable[Any]") -class MyCallable(Protocol[_T1]): +class Callable1(Protocol[_T1]): def __call__(self, __x: _T1) -> Any: ... -class MyDecorator(Protocol[_T2]): - def __call__(self, __x: MyCallable[_T2]) -> Any: +_T4 = TypeVar("_T4", bound=Callable1[Any]) + + +class Decorator1(Protocol[_T2]): + def __call__(self, __x: Callable1[_T2]) -> Any: ... -def decorates_my_callable(__x: MyDecorator[_T3]) -> MyDecorator[_T3]: +def decorator1(__x: Decorator1[_T3]) -> Decorator1[_T3]: ... -def my_decorator_inner(__x: Tv_my_callable) -> Tv_my_callable: +def func1(__x: _T4) -> _T4: ... -decorates_my_callable(my_decorator_inner) - +decorator1(func1) diff --git a/packages/pyright-internal/src/tests/samples/protocol29.py b/packages/pyright-internal/src/tests/samples/protocol29.py index ceb8cfefab68..3b0e907b3257 100644 --- a/packages/pyright-internal/src/tests/samples/protocol29.py +++ b/packages/pyright-internal/src/tests/samples/protocol29.py @@ -3,7 +3,7 @@ from functools import partial from typing_extensions import Protocol, Self -from typing import Any, Callable, Type, TypeVar +from typing import Any, Callable, TypeVar _T = TypeVar("_T", covariant=True) @@ -14,13 +14,13 @@ def func(self) -> Callable[..., _T]: ... def __new__( - cls: Type[Self], __func: Callable[..., _T], *args: Any, **kwargs: Any + cls: type[Self], __func: Callable[..., _T], *args: Any, **kwargs: Any ) -> Self: ... -def f(x: Partial[int]): +def func1(x: Partial[int]): ... -f(partial(int)) +func1(partial(int)) diff --git a/packages/pyright-internal/src/tests/samples/protocol3.py b/packages/pyright-internal/src/tests/samples/protocol3.py index c6df4756ff53..466bbce75f51 100644 --- a/packages/pyright-internal/src/tests/samples/protocol3.py +++ b/packages/pyright-internal/src/tests/samples/protocol3.py @@ -4,13 +4,13 @@ from typing import ContextManager, Protocol, TypeVar -class Foo1(Protocol): +class Class1(Protocol): @property def batch_shape(self) -> int: return 0 -class MockFoo1: +class MockClass1: def __init__(self, batch_shape: int): self._batch_shape = batch_shape @@ -20,16 +20,16 @@ def batch_shape(self) -> int: # This should not generate an error. -d: Foo1 = MockFoo1(batch_shape=1) +d: Class1 = MockClass1(batch_shape=1) -class Foo2(Protocol): +class Class2(Protocol): @property def batch_shape(self) -> int: return 0 -class MockFoo2: +class MockClass2: def __init__(self, batch_shape: int): self._batch_shape = batch_shape @@ -40,10 +40,10 @@ def batch_shape(self) -> float: # This should generate an error because the # type of the batch_shape property is not compatible. -e: Foo2 = MockFoo2(batch_shape=1) +e: Class2 = MockClass2(batch_shape=1) -class Foo3(Protocol): +class Class3(Protocol): @property def batch_shape(self) -> int: return 0 @@ -53,7 +53,7 @@ def batch_shape(self, value: int) -> None: pass -class MockFoo3: +class MockClass3: def __init__(self, batch_shape: int): self._batch_shape = batch_shape @@ -64,10 +64,10 @@ def batch_shape(self) -> int: # This should generate an error because it is missing # a setter. -f: Foo3 = MockFoo3(batch_shape=1) +f: Class3 = MockClass3(batch_shape=1) -class Foo4(Protocol): +class Class4(Protocol): @property def batch_shape(self) -> int: return 0 @@ -77,7 +77,7 @@ def batch_shape(self) -> None: pass -class MockFoo4: +class MockClass4: def __init__(self, batch_shape: int): self._batch_shape = batch_shape @@ -92,35 +92,43 @@ def batch_shape(self, value: int) -> None: # This should generate an error because it is missing # a deleter. -g: Foo4 = MockFoo4(batch_shape=1) +g: Class4 = MockClass4(batch_shape=1) _T_co = TypeVar("_T_co", covariant=True) _Self = TypeVar("_Self") -class Foo5: + +class Class5: @property - def real(self: _Self) -> _Self: ... + def real(self: _Self) -> _Self: + ... + -class MockFoo5(Protocol[_T_co]): +class MockClass5(Protocol[_T_co]): @property - def real(self) -> _T_co: ... + def real(self) -> _T_co: + ... -foo5 = Foo5() -h: MockFoo5[Foo5] = foo5 +foo5 = Class5() +h: MockClass5[Class5] = foo5 -_MockFoo6 = TypeVar("_MockFoo6", bound="MockFoo6") -_Foo6 = TypeVar("_Foo6", bound="Foo6") +P6 = TypeVar("P6", bound="MockClass6") +C6 = TypeVar("C6", bound="Class6") -class MockFoo6(Protocol): + +class MockClass6(Protocol): @property - def bar(self: _MockFoo6) -> ContextManager[_MockFoo6]: ... + def bar(self: P6) -> ContextManager[P6]: + ... + -class Foo6(): +class Class6: @property - def bar(self: _Foo6) -> ContextManager[_Foo6]: ... + def bar(self: C6) -> ContextManager[C6]: + ... -i: MockFoo6 = Foo6() +i: MockClass6 = Class6() diff --git a/packages/pyright-internal/src/tests/samples/protocol32.py b/packages/pyright-internal/src/tests/samples/protocol32.py index 96787c6a00b1..5f4b5999734a 100644 --- a/packages/pyright-internal/src/tests/samples/protocol32.py +++ b/packages/pyright-internal/src/tests/samples/protocol32.py @@ -11,6 +11,7 @@ class Base1(Protocol[Value]): def method1(self, default: Value) -> Value: ... + class Base2(Base1[Value], Protocol): def method2(self, default: Value) -> Value: ... @@ -43,8 +44,9 @@ def method1(self, default: Value) -> Value: def another(self, arg: Arg) -> None: return + def func2(arg: Arg, value: Value) -> Interface[Arg, Value]: - # This should generate an error because + # This should generate an error because # Implementation2 doesn't implement method2. return Implementation2[Arg, Value]() @@ -59,8 +61,9 @@ def method2(self, default: Value) -> Value: def another(self, arg: Arg) -> None: return + def func3(arg: Arg, value: Value) -> Interface[Arg, Value]: - # This should generate an error because + # This should generate an error because # Implementation3's signature doesn't match. return Implementation3[Arg, Value]() @@ -77,6 +80,6 @@ def method3(self, message: str) -> str: def method3(self, message: str | int): return message + class Implementation4(Base4): ... - diff --git a/packages/pyright-internal/src/tests/samples/protocol33.py b/packages/pyright-internal/src/tests/samples/protocol33.py index 3bf6bc75bb8d..4ff061400aeb 100644 --- a/packages/pyright-internal/src/tests/samples/protocol33.py +++ b/packages/pyright-internal/src/tests/samples/protocol33.py @@ -1,14 +1,14 @@ # This sample tests a protocol matching case that involves # a union of TypeVars. -from typing import Generic, TypeVar, Union, Protocol +from typing import Generic, TypeVar, Protocol T = TypeVar("T") U = TypeVar("U") class AProto(Generic[T, U], Protocol): - def f(self) -> Union[T, U]: + def f(self) -> T | U: ... def g(self) -> "AProto[T, U]": @@ -16,7 +16,7 @@ def g(self) -> "AProto[T, U]": class A(Generic[T, U]): - def f(self) -> Union[T, U]: + def f(self) -> T | U: raise NotImplementedError def g(self) -> AProto[T, U]: @@ -24,7 +24,7 @@ def g(self) -> AProto[T, U]: class BProto(Generic[T, U], Protocol): - def f(self) -> Union[T, U]: + def f(self) -> T | U: ... def g(self) -> "BProto[T, U]": @@ -32,7 +32,7 @@ def g(self) -> "BProto[T, U]": class B(Generic[T, U]): - def f(self) -> Union[T, U]: + def f(self) -> T | U: raise NotImplementedError def g(self) -> BProto[T, U]: diff --git a/packages/pyright-internal/src/tests/samples/protocol35.py b/packages/pyright-internal/src/tests/samples/protocol35.py index 0f335e454fea..0fc1c8a70867 100644 --- a/packages/pyright-internal/src/tests/samples/protocol35.py +++ b/packages/pyright-internal/src/tests/samples/protocol35.py @@ -1,5 +1,5 @@ # This sample tests that protocol compatibility caching produces -# the right result when the first example of protocol matching within +# the correct result when the first example of protocol matching within # the file does not require invariance enforcement but some later one # does. The cached protocol compatibility cannot be used in this case. diff --git a/packages/pyright-internal/src/tests/samples/protocol36.py b/packages/pyright-internal/src/tests/samples/protocol36.py index 5c6aea43d62a..7d0b7e22fb4b 100644 --- a/packages/pyright-internal/src/tests/samples/protocol36.py +++ b/packages/pyright-internal/src/tests/samples/protocol36.py @@ -4,15 +4,17 @@ _T_co = TypeVar("_T_co", covariant=True) -class _NestedSequence(Protocol[_T_co]): + +class NestedSequence(Protocol[_T_co]): @overload - def __getitem__(self, __i: int) -> _T_co | "_NestedSequence[_T_co]": + def __getitem__(self, __i: int) -> _T_co | "NestedSequence[_T_co]": ... + @overload - def __getitem__(self, __s: slice) -> "_NestedSequence[_T_co]": + def __getitem__(self, __s: slice) -> "NestedSequence[_T_co]": ... def func(v1: list[list[list[int]]]): - a: _NestedSequence[int] = v1 - b: _NestedSequence[int] = [[[3, 4]]] + a: NestedSequence[int] = v1 + b: NestedSequence[int] = [[[3, 4]]] diff --git a/packages/pyright-internal/src/tests/samples/protocol39.py b/packages/pyright-internal/src/tests/samples/protocol39.py index 0c59b6be2cd0..cf6c96aa3824 100644 --- a/packages/pyright-internal/src/tests/samples/protocol39.py +++ b/packages/pyright-internal/src/tests/samples/protocol39.py @@ -10,8 +10,8 @@ def __get__(self) -> Any: ... -def foo(cls: Any) -> None: +def func1(cls: Any) -> None: pass -v1: SupportsGet = foo +v1: SupportsGet = func1 diff --git a/packages/pyright-internal/src/tests/samples/protocol4.py b/packages/pyright-internal/src/tests/samples/protocol4.py index 059ec9f7d50e..8b1e0797c4c8 100644 --- a/packages/pyright-internal/src/tests/samples/protocol4.py +++ b/packages/pyright-internal/src/tests/samples/protocol4.py @@ -1,7 +1,7 @@ # This sample tests that instance and class variables # assigned within a Protocol method are flagged as errors. -from typing import ClassVar, List, Protocol +from typing import ClassVar, Protocol class ProtoA(Protocol): @@ -12,7 +12,7 @@ def method(self) -> None: self.a = 3 # This should be an error - self.temp: List[int] = [] + self.temp: list[int] = [] @classmethod def cls_method(cls) -> None: diff --git a/packages/pyright-internal/src/tests/samples/protocol5.py b/packages/pyright-internal/src/tests/samples/protocol5.py index 221326330061..3157801ce8cc 100644 --- a/packages/pyright-internal/src/tests/samples/protocol5.py +++ b/packages/pyright-internal/src/tests/samples/protocol5.py @@ -2,7 +2,7 @@ # the type checker allows instance variables that are initialized # in a method to be counted toward conformance to a defined Protocol. -from typing import Protocol, List +from typing import Protocol class Template(Protocol): diff --git a/packages/pyright-internal/src/tests/samples/protocol6.py b/packages/pyright-internal/src/tests/samples/protocol6.py index d2678fd8e393..e84c4aafd587 100644 --- a/packages/pyright-internal/src/tests/samples/protocol6.py +++ b/packages/pyright-internal/src/tests/samples/protocol6.py @@ -1,6 +1,6 @@ # This sample tests nested protocol definitions. -from typing import List, Literal, Protocol, TypeVar +from typing import Literal, Protocol, TypeVar _T1 = TypeVar("_T1") _T2 = TypeVar("_T2") @@ -9,7 +9,7 @@ class Animal(Protocol[_T1]): species: str - attributes: List[_T1] + attributes: list[_T1] class Mammal(Animal[_T2], Protocol): @@ -26,12 +26,12 @@ class CamelLike(Ungulate[bytes], Protocol): class Sloth: species: str - attributes: List[str] + attributes: list[str] class Armadillo: species: str - attributes: List[bytes] + attributes: list[bytes] class Tapir: @@ -40,13 +40,13 @@ class Tapir: class Camel: species: Literal["camel"] - attributes: List[bytes] + attributes: list[bytes] type_of_hooves: bytes class Cow: species: str - attributes: List[str] + attributes: list[str] type_of_hooves: str diff --git a/packages/pyright-internal/src/tests/samples/protocol9.py b/packages/pyright-internal/src/tests/samples/protocol9.py index d1cad71ddb69..6d3bb9352f5a 100644 --- a/packages/pyright-internal/src/tests/samples/protocol9.py +++ b/packages/pyright-internal/src/tests/samples/protocol9.py @@ -1,17 +1,17 @@ # This sample tests a protocol class that refers to itself. -from typing import Optional, Protocol +from typing import Protocol class TreeLike(Protocol): value: int @property - def left(self) -> Optional["TreeLike"]: + def left(self) -> "TreeLike | None": ... @property - def right(self) -> Optional["TreeLike"]: + def right(self) -> "TreeLike | None": ... @@ -19,17 +19,17 @@ class SimpleTree: value: int @property - def left(self) -> Optional["SimpleTree"]: + def left(self) -> "SimpleTree | None": return self._left @property - def right(self) -> Optional["SimpleTree"]: + def right(self) -> "SimpleTree | None": return self._right def __init__(self, value: int) -> None: self.value = value - self._left: Optional["SimpleTree"] = None - self._right: Optional["SimpleTree"] = None + self._left: SimpleTree | None = None + self._right: SimpleTree | None = None root: TreeLike = SimpleTree(0) diff --git a/packages/pyright-internal/src/tests/samples/protocolModule1.py b/packages/pyright-internal/src/tests/samples/protocolModule1.py index f86fbeda8f2d..ff852f1a5de4 100644 --- a/packages/pyright-internal/src/tests/samples/protocolModule1.py +++ b/packages/pyright-internal/src/tests/samples/protocolModule1.py @@ -1,10 +1,8 @@ # This sample is used in conjunction with protocolModule2.py. -from typing import Union - var_1: int = 3 -var_2: Union[int, str] = "hello" +var_2: int | str = "hello" def func_1(a: int, b: str) -> str: diff --git a/packages/pyright-internal/src/tests/samples/protocolModule2.py b/packages/pyright-internal/src/tests/samples/protocolModule2.py index bbf8c7df2565..32c145c9b4f3 100644 --- a/packages/pyright-internal/src/tests/samples/protocolModule2.py +++ b/packages/pyright-internal/src/tests/samples/protocolModule2.py @@ -1,6 +1,6 @@ # This sample tests protocol matching for modules. -from typing import Protocol, Type, TypeVar, Union, runtime_checkable +from typing import Protocol, TypeVar, runtime_checkable from . import protocolModule1 import datetime from importlib import import_module @@ -9,7 +9,7 @@ @runtime_checkable class P1(Protocol): var_1: int - var_2: Union[int, str] + var_2: int | str def func_1(self, a: int, b: str) -> str: ... @@ -61,7 +61,7 @@ class NonProtocol: # Test type narrowing of module symbols for isinstance checks. -def func1(x: Type[_T]): +def func1(x: type[_T]): if isinstance(datetime, (P1, P2, NonProtocol, x)): reveal_type(datetime, expected_text="P1 | P2 | _T@func1") else: diff --git a/packages/pyright-internal/src/tests/samples/pseudoGeneric1.py b/packages/pyright-internal/src/tests/samples/pseudoGeneric1.py index ae086f42efba..8a0c0b8ffa13 100644 --- a/packages/pyright-internal/src/tests/samples/pseudoGeneric1.py +++ b/packages/pyright-internal/src/tests/samples/pseudoGeneric1.py @@ -5,11 +5,7 @@ class ClassA: - def __init__( - self, - name, - description=_DEFAULT_VALUE, - ): + def __init__(self, name, description=_DEFAULT_VALUE): ... diff --git a/packages/pyright-internal/src/tests/samples/pyrightComment1.py b/packages/pyright-internal/src/tests/samples/pyrightComment1.py index fb7a9c6d10c4..11dfca8f3198 100644 --- a/packages/pyright-internal/src/tests/samples/pyrightComment1.py +++ b/packages/pyright-internal/src/tests/samples/pyrightComment1.py @@ -22,7 +22,7 @@ a = 1 # pyright: reportGeneralTypeIssues=false -def foo(): +def func1(): # This should generate an error because it's not on its own line. # pyright: reportGeneralTypeIssues=false pass diff --git a/packages/pyright-internal/src/tests/samples/pyrightIgnore1.py b/packages/pyright-internal/src/tests/samples/pyrightIgnore1.py index 271ae65c02ae..af108ce63aba 100644 --- a/packages/pyright-internal/src/tests/samples/pyrightIgnore1.py +++ b/packages/pyright-internal/src/tests/samples/pyrightIgnore1.py @@ -1,10 +1,9 @@ # This sample tests the # pyright: ignore comment. import sys -from typing import Optional -def foo(self, x: Optional[int]) -> str: +def func1(self, x: int | None) -> str: # This should suppress the error x + "hi" # pyright: ignore - test diff --git a/packages/pyright-internal/src/tests/samples/pyrightIgnore2.py b/packages/pyright-internal/src/tests/samples/pyrightIgnore2.py index 0ea0ced52e30..3bc5ebec9b19 100644 --- a/packages/pyright-internal/src/tests/samples/pyrightIgnore2.py +++ b/packages/pyright-internal/src/tests/samples/pyrightIgnore2.py @@ -1,10 +1,8 @@ # This sample tests the use of a pyright ignore comment in conjunction # with the reportUnnecessaryTypeIgnoreComment mechanism. -from typing import Optional - -def foo(self, x: Optional[int]) -> str: +def func1(self, x: int | None) -> str: # This should suppress the error v1 = x + "hi" # pyright: ignore - test diff --git a/packages/pyright-internal/src/tests/samples/recursiveTypeAlias1.py b/packages/pyright-internal/src/tests/samples/recursiveTypeAlias1.py index 357686f7133e..05cf1f8f623f 100644 --- a/packages/pyright-internal/src/tests/samples/recursiveTypeAlias1.py +++ b/packages/pyright-internal/src/tests/samples/recursiveTypeAlias1.py @@ -1,8 +1,8 @@ # This sample tests Pyright's handling of recursive type aliases. -from typing import Dict, List, Mapping, TypeVar, Union +from typing import Mapping, TypeVar, Union -MyTree = List[Union["MyTree", int]] +MyTree = list[Union["MyTree", int]] t1: MyTree = [1, 2, 3, [3, 4], [[3], 5]] @@ -22,7 +22,7 @@ # This should generate an error because str isn't compatible. i2 = "hi" -Foo = Union[bool, List["Foo"], Dict["Foo", "Foo"]] +Foo = Union[bool, list["Foo"], dict["Foo", "Foo"]] bar1: Foo = [True, [True, False]] bar2: Foo = [True, [True], {True: False}] @@ -33,7 +33,7 @@ baz2: Foo = [True, [True], {True: "False"}] baz4: Foo = {True: ["False"]} -Json = Union[None, int, str, float, List["Json"], Dict[str, "Json"]] +Json = Union[None, int, str, float, list["Json"], dict[str, "Json"]] # This should generate an error a1: Json = {"a": 1, "b": 3j} diff --git a/packages/pyright-internal/src/tests/samples/recursiveTypeAlias10.py b/packages/pyright-internal/src/tests/samples/recursiveTypeAlias10.py index e977dba883ec..a43a2925766c 100644 --- a/packages/pyright-internal/src/tests/samples/recursiveTypeAlias10.py +++ b/packages/pyright-internal/src/tests/samples/recursiveTypeAlias10.py @@ -30,6 +30,3 @@ def func3(v: Optional[JsonVal1]): x: Optional[JsonVal2] = v return x - - - \ No newline at end of file diff --git a/packages/pyright-internal/src/tests/samples/recursiveTypeAlias12.py b/packages/pyright-internal/src/tests/samples/recursiveTypeAlias12.py index b8ad6084690c..963e590bc7bb 100644 --- a/packages/pyright-internal/src/tests/samples/recursiveTypeAlias12.py +++ b/packages/pyright-internal/src/tests/samples/recursiveTypeAlias12.py @@ -11,14 +11,18 @@ class TraceFunctionProto(Protocol): def __call__(self, frame: FrameType, event: str, arg: Any) -> Self | None: ... + TraceFunction: TypeAlias = Callable[[FrameType, str, Any], "TraceFunction | None"] -def settrace(tf: TraceFunction | None) -> None: ... + +def settrace(tf: TraceFunction | None) -> None: + ... + def func1(frame: FrameType, event: str, arg: Any) -> TraceFunction: ... + def func2(tf: TraceFunctionProto | None): settrace(tf) settrace(func1) - diff --git a/packages/pyright-internal/src/tests/samples/recursiveTypeAlias14.py b/packages/pyright-internal/src/tests/samples/recursiveTypeAlias14.py index 95e6bc924200..633c6432fa2f 100644 --- a/packages/pyright-internal/src/tests/samples/recursiveTypeAlias14.py +++ b/packages/pyright-internal/src/tests/samples/recursiveTypeAlias14.py @@ -14,6 +14,7 @@ def func1() -> NestedIntList: result = [result] return result + def func2() -> NestedIntList: # This should generate an error. result: NestedIntList = "" diff --git a/packages/pyright-internal/src/tests/samples/recursiveTypeAlias2.py b/packages/pyright-internal/src/tests/samples/recursiveTypeAlias2.py index 82fe7653ff7e..3d1146c2108c 100644 --- a/packages/pyright-internal/src/tests/samples/recursiveTypeAlias2.py +++ b/packages/pyright-internal/src/tests/samples/recursiveTypeAlias2.py @@ -1,12 +1,12 @@ # This sample tests Pyright's handling of recursive type aliases # that are also generic. -from typing import List, TypeVar, Union +from typing import TypeVar, Union _T1 = TypeVar("_T1", str, int) _T2 = TypeVar("_T2") -GenericTypeAlias1 = List[Union["GenericTypeAlias1[_T1]", _T1]] +GenericTypeAlias1 = list[Union["GenericTypeAlias1[_T1]", _T1]] SpecializedTypeAlias1 = GenericTypeAlias1[str] @@ -22,7 +22,7 @@ b2: GenericTypeAlias1[str] = ["hi", [2.4]] -GenericTypeAlias2 = List[Union["GenericTypeAlias2[_T1, _T2]", _T1, _T2]] +GenericTypeAlias2 = list[Union["GenericTypeAlias2[_T1, _T2]", _T1, _T2]] c2: GenericTypeAlias2[str, int] = [[3, ["hi"]], "hi"] diff --git a/packages/pyright-internal/src/tests/samples/recursiveTypeAlias3.py b/packages/pyright-internal/src/tests/samples/recursiveTypeAlias3.py index ddc3c80b5488..6fdb37bf1c88 100644 --- a/packages/pyright-internal/src/tests/samples/recursiveTypeAlias3.py +++ b/packages/pyright-internal/src/tests/samples/recursiveTypeAlias3.py @@ -1,10 +1,10 @@ # This sample tests Pyright's handling of recursive type aliases. -from typing import List, TypeAlias, Union +from typing import TypeAlias, Union # This should generate an error because the forward reference # type needs to be in quotes. -GenericClass0 = List[Union[GenericClass0, int]] +GenericClass0 = list[GenericClass0 | int] # This should generate an error because the type alias directly # refers to itself. diff --git a/packages/pyright-internal/src/tests/samples/recursiveTypeAlias4.py b/packages/pyright-internal/src/tests/samples/recursiveTypeAlias4.py index 0a0c3d4d8305..8bf6b994e8d8 100644 --- a/packages/pyright-internal/src/tests/samples/recursiveTypeAlias4.py +++ b/packages/pyright-internal/src/tests/samples/recursiveTypeAlias4.py @@ -2,50 +2,50 @@ # pyright: strict, reportUnusedVariable=false -from typing import Dict, Generator, List, Optional, Union +from typing import Generator -JSONArray = List["JSONType"] -JSONObject = Dict[str, "JSONType"] +JSONArray = list["JSONType"] +JSONObject = dict[str, "JSONType"] -JSONPrimitive = Union[str, float, int, bool, None] -JSONStructured = Union[JSONArray, JSONObject] +JSONPrimitive = str | float | int | bool | None +JSONStructured = JSONArray | JSONObject -JSONType = Union[JSONPrimitive, JSONStructured] +JSONType = JSONPrimitive | JSONStructured # Using type alias checking for list: def f2(args: JSONStructured): - if isinstance(args, List): + if isinstance(args, list): reveal_type( args, - expected_text="List[str | float | int | bool | JSONArray | Dict[str, JSONType] | None]", + expected_text="list[str | float | int | bool | JSONArray | dict[str, JSONType] | None]", ) else: reveal_type( args, - expected_text="Dict[str, str | float | int | bool | List[JSONType] | JSONObject | None]", + expected_text="dict[str, str | float | int | bool | list[JSONType] | JSONObject | None]", ) dargs: JSONObject = args # Using type alias checking for dict: def f3(args: JSONStructured): - if isinstance(args, Dict): + if isinstance(args, dict): reveal_type( args, - expected_text="Dict[str, str | float | int | bool | List[JSONType] | JSONObject | None]", + expected_text="dict[str, str | float | int | bool | list[JSONType] | JSONObject | None]", ) else: reveal_type( args, - expected_text="List[str | float | int | bool | JSONArray | Dict[str, JSONType] | None]", + expected_text="list[str | float | int | bool | JSONArray | dict[str, JSONType] | None]", ) largs: JSONArray = args # Using type alias for "is None" narrowing: -LinkedList = Optional[tuple[int, "LinkedList"]] +LinkedList = tuple[int, "LinkedList"] | None def g(xs: LinkedList) -> Generator[int, None, None]: diff --git a/packages/pyright-internal/src/tests/samples/recursiveTypeAlias7.py b/packages/pyright-internal/src/tests/samples/recursiveTypeAlias7.py index 77ecc936f5ec..abde0df34217 100644 --- a/packages/pyright-internal/src/tests/samples/recursiveTypeAlias7.py +++ b/packages/pyright-internal/src/tests/samples/recursiveTypeAlias7.py @@ -7,9 +7,9 @@ A = Union[str, Dict[str, "A"]] -def foo(x: A): +def func1(x: A): if isinstance(x, str): print(x) else: for _, v in x.items(): - foo(v) + func1(v) diff --git a/packages/pyright-internal/src/tests/samples/required2.py b/packages/pyright-internal/src/tests/samples/required2.py index 6b71f40e6c8d..7318d74b5003 100644 --- a/packages/pyright-internal/src/tests/samples/required2.py +++ b/packages/pyright-internal/src/tests/samples/required2.py @@ -3,7 +3,7 @@ # pyright: reportMissingModuleSource=false -from typing import Literal, Optional, Type, TypedDict, Annotated +from typing import Literal, TypedDict, Annotated from typing_extensions import NotRequired, Required @@ -11,10 +11,10 @@ class TD1(TypedDict, total=False): a: Annotated["Required[int]", ""] b: Annotated[NotRequired[str], ""] c: "Required[int | str]" - d: Required[Optional[str]] + d: Required[str | None] e: Required[Literal[1, 2, 3]] f: Required[None] - g: Required[Type[int]] + g: Required[type[int]] td1_1: TD1 = {"a": 3, "c": "hi", "d": None, "e": 3, "f": None, "g": int} @@ -42,10 +42,10 @@ class TD2(TypedDict, total=True): a: Required[int] b: NotRequired[str] c: Required[int | str] - d: NotRequired[Optional[str]] + d: NotRequired[str | None] e: NotRequired[Literal[1, 2, 3]] f: NotRequired[None] - g: NotRequired[Type[int]] + g: NotRequired[type[int]] td2_1: TD2 = {"a": 3, "c": "hi", "d": None, "e": 3, "f": None, "g": int} diff --git a/packages/pyright-internal/src/tests/samples/required3.py b/packages/pyright-internal/src/tests/samples/required3.py index f2d6a5a819ac..efad5fd2db4c 100644 --- a/packages/pyright-internal/src/tests/samples/required3.py +++ b/packages/pyright-internal/src/tests/samples/required3.py @@ -10,7 +10,7 @@ v1_0: Example1 = {"required": 1} -# This should generage an error. +# This should generate an error. v1_1: Example1 = {"not_required": 1} Example2 = TypedDict("Example", required=Required[int], not_required=NotRequired[int]) @@ -18,5 +18,5 @@ v2_0: Example2 = {"required": 1} -# This should generage an error. +# This should generate an error. v2_1: Example2 = {"not_required": 1} diff --git a/packages/pyright-internal/src/tests/samples/returnTypes1.py b/packages/pyright-internal/src/tests/samples/returnTypes1.py index ed693bc88aee..66d5aff5c2ef 100644 --- a/packages/pyright-internal/src/tests/samples/returnTypes1.py +++ b/packages/pyright-internal/src/tests/samples/returnTypes1.py @@ -1,26 +1,27 @@ # This sample tests basic return type analysis and error reporting. -def add(a: int, b: int) -> int: +def func1(a: int, b: int) -> int: c = float(a + b) # This should generate an error: # Expression of type 'float' cannot be assigned to return type 'int' return c -def addf(a: float, b: float) -> float: +def func2(a: float, b: float) -> float: c = float(a + b) return c # This should generate an error: # Argument of type 'float' cannot be assigned to parameter of type 'int' -add(3.4, 5) +func1(3.4, 5) # This should be fine -addf(3, 5) +func2(3, 5) + # This should not produce any error because the function's suite is empty. -def noReturnIsFine() -> bool: +def func3() -> bool: "Doc strings are allowed" ... diff --git a/packages/pyright-internal/src/tests/samples/returnTypes2.py b/packages/pyright-internal/src/tests/samples/returnTypes2.py index 42ccf3c224e3..aa37b8c2d5a9 100644 --- a/packages/pyright-internal/src/tests/samples/returnTypes2.py +++ b/packages/pyright-internal/src/tests/samples/returnTypes2.py @@ -1,6 +1,7 @@ # This sample tests the case where return type inference encounters # recursion. + class Grammar: @staticmethod def A(): diff --git a/packages/pyright-internal/src/tests/samples/self1.py b/packages/pyright-internal/src/tests/samples/self1.py index d3cc7cd478b4..791b05b6e343 100644 --- a/packages/pyright-internal/src/tests/samples/self1.py +++ b/packages/pyright-internal/src/tests/samples/self1.py @@ -1,11 +1,12 @@ # This sample tests various error conditions for the Self type -from typing import Callable, Generic, Type, TypeVar +from typing import Callable, TypeVar from typing_extensions import Self T = TypeVar("T") + # This should generate an error because Self can't be used in this context. class A(Self): ... @@ -55,7 +56,7 @@ def method4(self: T, a: Self) -> T: return self @classmethod - def method5(cls) -> Type[Self]: + def method5(cls) -> type[Self]: return cls @classmethod @@ -63,13 +64,13 @@ def method6(cls, a: Self) -> None: ... @classmethod - def method7(cls: Type[Self]) -> Type[Self]: + def method7(cls: type[Self]) -> type[Self]: return cls # This should generate an error because Self can't be used with # methods that declare a non-Self type for "self". @classmethod - def method8(cls: Type[T], a: Self) -> Type[T]: + def method8(cls: type[T], a: Self) -> type[T]: # This should generate an error because Self can't be used with # methods that declare a non-Self type for "self". x: Self diff --git a/packages/pyright-internal/src/tests/samples/self2.py b/packages/pyright-internal/src/tests/samples/self2.py index 91e27d2d4a60..78f31b8330cc 100644 --- a/packages/pyright-internal/src/tests/samples/self2.py +++ b/packages/pyright-internal/src/tests/samples/self2.py @@ -1,6 +1,6 @@ # This sample tests the usage of the Self type. -from typing import Callable, Dict, Generic, ParamSpec, Protocol, Type, TypeVar +from typing import Callable, Generic, ParamSpec, Protocol, TypeVar from typing_extensions import Self from dataclasses import dataclass @@ -22,11 +22,11 @@ def method2(self) -> Self: return self @classmethod - def method3(cls: Type[Self]) -> Type[Self]: + def method3(cls: type[Self]) -> type[Self]: return cls @classmethod - def method4(cls) -> Type[Self]: + def method4(cls) -> type[Self]: return cls @@ -44,7 +44,7 @@ def set_scale(self, scale: float) -> Self: return self @classmethod - def from_config(cls, config: Dict[str, float]) -> Self: + def from_config(cls, config: dict[str, float]) -> Self: return cls() @@ -65,7 +65,7 @@ def set_scale(self: Self, scale: float) -> Self: return self @classmethod - def from_config(cls: Type[Self], config: Dict[str, float]) -> Self: + def from_config(cls: type[Self], config: dict[str, float]) -> Self: return cls() def difference(self: Self, other: Self) -> float: diff --git a/packages/pyright-internal/src/tests/samples/slots2.py b/packages/pyright-internal/src/tests/samples/slots2.py index 4c0583d6f256..0062a5d2bdbd 100644 --- a/packages/pyright-internal/src/tests/samples/slots2.py +++ b/packages/pyright-internal/src/tests/samples/slots2.py @@ -3,6 +3,7 @@ from dataclasses import dataclass, field + class NoSlots1: pass @@ -30,9 +31,8 @@ class Slots2(Slots1): @dataclass class Slots3: - __slots__ = ('values',) + __slots__ = ("values",) # This should not generate an error because class variables # in a dataclass are replaced by instance variables. values: list[int] = field(default_factory=list) - diff --git a/packages/pyright-internal/src/tests/samples/solver10.py b/packages/pyright-internal/src/tests/samples/solver10.py index 9133b6c10f11..068f4187903b 100644 --- a/packages/pyright-internal/src/tests/samples/solver10.py +++ b/packages/pyright-internal/src/tests/samples/solver10.py @@ -4,13 +4,13 @@ # We need to validate that the type inference for lists # is not over-narrowing when matching these literals. -from typing import Callable, List, Tuple, TypeVar +from typing import Callable, TypeVar _T = TypeVar("_T") -def extend_if(xs: List[_T], ys: List[Tuple[_T, bool]]) -> List[_T]: +def extend_if(xs: list[_T], ys: list[tuple[_T, bool]]) -> list[_T]: raise NotImplementedError() diff --git a/packages/pyright-internal/src/tests/samples/solver13.py b/packages/pyright-internal/src/tests/samples/solver13.py index 2ced37343e53..e41124d766a3 100644 --- a/packages/pyright-internal/src/tests/samples/solver13.py +++ b/packages/pyright-internal/src/tests/samples/solver13.py @@ -1,6 +1,6 @@ # This sample tests that type variables chain properly. -from typing import Generic, Iterable, Iterator, Tuple, TypeVar +from typing import Generic, Iterable, Iterator, TypeVar from itertools import chain T = TypeVar("T") @@ -29,5 +29,5 @@ class ClassB(Generic[T]): def __init__(self, xs: Iterable[T]) -> None: self.xs = xs - def indexed(self) -> "ClassB[Tuple[int, T]]": + def indexed(self) -> "ClassB[tuple[int, T]]": return ClassB(enumerate(self.xs)) diff --git a/packages/pyright-internal/src/tests/samples/solver15.py b/packages/pyright-internal/src/tests/samples/solver15.py index 7515c3463315..dc76b2f068a2 100644 --- a/packages/pyright-internal/src/tests/samples/solver15.py +++ b/packages/pyright-internal/src/tests/samples/solver15.py @@ -1,7 +1,7 @@ # This sample tests the handling of a bound TypeVar that is used # in a Type[X] statement. -from typing import Callable, Generic, TypeVar, Type, Union +from typing import Callable, Generic, TypeVar class Base: @@ -11,12 +11,12 @@ class Base: T = TypeVar("T", bound=Base) -def register(state_name: str, state: Type[T]): +def register(state_name: str, state: type[T]): ... -def register_state(state_name: str) -> Callable[[Type[T]], Type[T]]: - def decorator(state: Type[T]) -> Type[T]: +def register_state(state_name: str) -> Callable[[type[T]], type[T]]: + def decorator(state: type[T]) -> type[T]: register(state_name, state) return state @@ -30,12 +30,12 @@ class F: E = TypeVar("E", bound=F) -def coercer_method(value: Union[E, str], enum: Type[E]) -> E: +def coercer_method(value: E | str, enum: type[E]) -> E: ... class C(Generic[E]): - e_type: Type[E] + e_type: type[E] - def coerce(self, e_type: Type[E], value: Union[E, str]) -> E: + def coerce(self, e_type: type[E], value: E | str) -> E: return coercer_method(value, self.e_type) diff --git a/packages/pyright-internal/src/tests/samples/solver17.py b/packages/pyright-internal/src/tests/samples/solver17.py index 47863c248e06..a056fc9d51b2 100644 --- a/packages/pyright-internal/src/tests/samples/solver17.py +++ b/packages/pyright-internal/src/tests/samples/solver17.py @@ -2,29 +2,29 @@ # are unions and are being compared using invariant constraints # and the dest type contains a type variable. -from typing import Pattern, Sequence, TypeVar, List, Optional, Union +from typing import Pattern, Sequence, TypeVar _T = TypeVar("_T") -def func1(v: List[Optional[_T]]) -> _T: +def func1(v: list[_T | None]) -> _T: ... -def func2(v: List[Optional[Union[_T, str]]]) -> _T: +def func2(v: list[_T | str | None]) -> _T: ... -v1: List[Optional[int]] = [1, None] +v1: list[int | None] = [1, None] r1 = func1(v1) reveal_type(r1, expected_text="int") -v2: List[Optional[Union[int, str]]] = [1, None] +v2: list[int | str | None] = [1, None] r2_1 = func1(v2) reveal_type(r2_1, expected_text="int | str") r2_2 = func2(v2) reveal_type(r2_2, expected_text="int") -v3: List[Union[str, Sequence[Pattern]]] = [""] +v3: list[str | Sequence[Pattern]] = [""] diff --git a/packages/pyright-internal/src/tests/samples/solver19.py b/packages/pyright-internal/src/tests/samples/solver19.py index 166fcd357ae8..972e6c214e6f 100644 --- a/packages/pyright-internal/src/tests/samples/solver19.py +++ b/packages/pyright-internal/src/tests/samples/solver19.py @@ -1,27 +1,27 @@ # This sample tests the handling of Type[T] matching and replacement. -from typing import Generator, List, Type, TypeVar, Union +from typing import Generator, TypeVar -class LI(List[int]): +class LI(list[int]): pass -class LS(List[str]): +class LS(list[str]): pass _T1 = TypeVar("_T1") -class MyList(List[Union[LI, LS]]): - def get_generator(self, *, type_: Type[_T1]) -> Generator[_T1, None, None]: +class MyList(list[LI | LS]): + def get_generator(self, *, type_: type[_T1]) -> Generator[_T1, None, None]: for elem in self: if isinstance(elem, type_): yield elem -def same(other: Union[LI, LS]): +def same(other: LI | LS): for elem in MyList().get_generator(type_=other.__class__): for v in elem: print(v) diff --git a/packages/pyright-internal/src/tests/samples/solver20.py b/packages/pyright-internal/src/tests/samples/solver20.py index fdf9a5a18345..e9e9f1440c24 100644 --- a/packages/pyright-internal/src/tests/samples/solver20.py +++ b/packages/pyright-internal/src/tests/samples/solver20.py @@ -1,9 +1,9 @@ # This sample tests the case where a type variable is bound to a union. -from typing import Callable, TypeVar, Union +from typing import Callable, TypeVar T = TypeVar("T") -IntStr = Union[str, int] +IntStr = str | int T1 = TypeVar("T1", bound=IntStr) T2 = TypeVar("T2", bound=IntStr) diff --git a/packages/pyright-internal/src/tests/samples/solver24.py b/packages/pyright-internal/src/tests/samples/solver24.py index 2979ab7c3125..9addd6b315f9 100644 --- a/packages/pyright-internal/src/tests/samples/solver24.py +++ b/packages/pyright-internal/src/tests/samples/solver24.py @@ -1,7 +1,7 @@ # This sample tests the case where the constraint solver's solution involves # a union of type variables. -from typing import Generic, TypeVar, Union, cast +from typing import Generic, TypeVar V = TypeVar("V") V_co = TypeVar("V_co", covariant=True) @@ -17,7 +17,7 @@ def __init__(self, x: ClassA[V_co]): pass -def func1(a: ClassA[V], b: ClassA[U], c: bool) -> ClassB[Union[V, U]]: +def func1(a: ClassA[V], b: ClassA[U], c: bool) -> ClassB[V | U]: x: ClassA[V | U] = a reveal_type(x, expected_text="ClassA[V@func1]") if c: diff --git a/packages/pyright-internal/src/tests/samples/solver8.py b/packages/pyright-internal/src/tests/samples/solver8.py index c37df14e7d3a..67830444bae8 100644 --- a/packages/pyright-internal/src/tests/samples/solver8.py +++ b/packages/pyright-internal/src/tests/samples/solver8.py @@ -1,12 +1,12 @@ # This sample tests the constraint solver's special-case handling of # Optional[T] within a function. -from typing import Optional, TypeVar +from typing import TypeVar _T = TypeVar("_T") -def func1(v: Optional[_T]) -> _T: +def func1(v: _T | None) -> _T: if v is None: raise ValueError return v @@ -18,7 +18,7 @@ def func2(v: _T) -> _T: return v -f: Optional[int] = None +f: int | None = None a: int = func1(f) diff --git a/packages/pyright-internal/src/tests/samples/solver9.py b/packages/pyright-internal/src/tests/samples/solver9.py index 2885e2463efa..f82eab0eaac6 100644 --- a/packages/pyright-internal/src/tests/samples/solver9.py +++ b/packages/pyright-internal/src/tests/samples/solver9.py @@ -1,21 +1,21 @@ # This sample tests that Optional types can be matched # to Type[T] expressions by the constraint solver. -from typing import Callable, Generic, Optional, Type, TypeVar +from typing import Callable, Generic, Optional, TypeVar _T1 = TypeVar("_T1") _T2 = TypeVar("_T2", bound=None) _T3 = TypeVar("_T3") -def func1(a: Type[_T1]) -> _T1: +def func1(a: type[_T1]) -> _T1: return a() a = func1(Optional[int]) -def func2(a: Type[_T2]) -> Type[_T2]: +def func2(a: type[_T2]) -> type[_T2]: return a @@ -31,7 +31,7 @@ def __init__(self, value: _T1) -> None: ... @classmethod - def get(cls: Type[_T3]) -> Type[_T3]: + def get(cls: type[_T3]) -> type[_T3]: return cls @@ -39,7 +39,7 @@ class ClassB(ClassA): pass -def func3(value: _T1) -> Type[ClassA[_T1]]: +def func3(value: _T1) -> type[ClassA[_T1]]: v1 = ClassA(value) v2 = type(v1) reveal_type(v2, expected_text="type[ClassA[_T1@func3]]") diff --git a/packages/pyright-internal/src/tests/samples/solverLiteral1.py b/packages/pyright-internal/src/tests/samples/solverLiteral1.py index db892a9b9f06..ea9c29bdacb4 100644 --- a/packages/pyright-internal/src/tests/samples/solverLiteral1.py +++ b/packages/pyright-internal/src/tests/samples/solverLiteral1.py @@ -1,10 +1,10 @@ # This sample tests the case that exercises some of the heuristics that # determine whether a solved TypeVar should retain a literal type. -from typing import Callable, Dict, Generic, Literal, Tuple, TypeVar +from typing import Callable, Generic, Literal, TypeVar -FileChanges = Dict[str, Literal["created", "edited", "removed"]] +FileChanges = dict[str, Literal["created", "edited", "removed"]] changes: FileChanges = {} changes.update({filename: "removed" for filename in ["foo.py", "bar.py"]}) @@ -35,7 +35,7 @@ def func3(value: _T) -> Callable[[_T], None]: ... -x: Callable[[Tuple[bool]], None] = func3((True,)) +x: Callable[[tuple[bool]], None] = func3((True,)) def func4(v: _T, f: Callable[[_T], None]): diff --git a/packages/pyright-internal/src/tests/samples/solverScoring2.py b/packages/pyright-internal/src/tests/samples/solverScoring2.py index 2ce5f5bbfb40..7f4ad0dd3a55 100644 --- a/packages/pyright-internal/src/tests/samples/solverScoring2.py +++ b/packages/pyright-internal/src/tests/samples/solverScoring2.py @@ -3,7 +3,7 @@ # according to PEP 484, but pyright has code in place to find the # "least complex" answer. -from typing import Any, Generic, List, TypeVar, Union +from typing import Any, Generic, TypeVar, Union T1 = TypeVar("T1") @@ -20,52 +20,52 @@ def some_func(x: Wrapper[T1]) -> Wrapper[T1]: return ensure_wrapped(x) -def func1a(value: List[Union[T1, List[T1]]]) -> T1: +def func1a(value: list[Union[T1, list[T1]]]) -> T1: ... -def func2a(value: List[Union[float, List[float]]]): +def func2a(value: list[Union[float, list[float]]]): x = func1a(value) reveal_type(x, expected_text="float") -def func3a(value: List[Union[str, List[float]]]): +def func3a(value: list[Union[str, list[float]]]): # This should generate an error func1a(value) -def func4a(value: List[Union[float, str, List[Union[float, str]]]]): +def func4a(value: list[Union[float, str, list[Union[float, str]]]]): x = func1a(value) reveal_type(x, expected_text="float | str") -def func1b(value: List[Union[int, List[T1]]]) -> T1: +def func1b(value: list[Union[int, list[T1]]]) -> T1: ... -def func2b(value: List[Union[int, List[float]]]): +def func2b(value: list[Union[int, list[float]]]): x = func1b(value) reveal_type(x, expected_text="float") -def func3b(value: List[Union[str, List[float]]]): +def func3b(value: list[Union[str, list[float]]]): # This should generate an error func1b(value) -def ensure_list(value: Union[T1, List[T1]]) -> List[T1]: +def ensure_list(value: Union[T1, list[T1]]) -> list[T1]: ... def func4( - v1: list, v2: List[Any], v3: List[None], v4: Any, v5: int, v6: T1, v7: List[T1] + v1: list, v2: list[Any], v3: list[None], v4: Any, v5: int, v6: T1, v7: list[T1] ) -> T1: - reveal_type(ensure_list(v1), expected_text="List[Unknown]") - reveal_type(ensure_list(v2), expected_text="List[Any]") - reveal_type(ensure_list(v3), expected_text="List[None]") - reveal_type(ensure_list(v4), expected_text="List[Any]") - reveal_type(ensure_list(v5), expected_text="List[int]") - reveal_type(ensure_list(v6), expected_text="List[T1@func4]") - reveal_type(ensure_list(v7), expected_text="List[T1@func4]") + reveal_type(ensure_list(v1), expected_text="list[Unknown]") + reveal_type(ensure_list(v2), expected_text="list[Any]") + reveal_type(ensure_list(v3), expected_text="list[None]") + reveal_type(ensure_list(v4), expected_text="list[Any]") + reveal_type(ensure_list(v5), expected_text="list[int]") + reveal_type(ensure_list(v6), expected_text="list[T1@func4]") + reveal_type(ensure_list(v7), expected_text="list[T1@func4]") return v6 diff --git a/packages/pyright-internal/src/tests/samples/solverScoring3.py b/packages/pyright-internal/src/tests/samples/solverScoring3.py index 26e3e0daa672..5cd2d1d5e457 100644 --- a/packages/pyright-internal/src/tests/samples/solverScoring3.py +++ b/packages/pyright-internal/src/tests/samples/solverScoring3.py @@ -1,12 +1,12 @@ # This sample tests the case where the constraint solver can choose one # of several types that satisfy the constraints. -from typing import TypeVar, Union +from typing import TypeVar T = TypeVar("T") -def to_list(t: Union[list[T], T]) -> list[T]: +def to_list(t: list[T] | T) -> list[T]: ... diff --git a/packages/pyright-internal/src/tests/samples/staticExpressions1.py b/packages/pyright-internal/src/tests/samples/staticExpression1.py similarity index 99% rename from packages/pyright-internal/src/tests/samples/staticExpressions1.py rename to packages/pyright-internal/src/tests/samples/staticExpression1.py index 63a4416ae183..400bb1546058 100644 --- a/packages/pyright-internal/src/tests/samples/staticExpressions1.py +++ b/packages/pyright-internal/src/tests/samples/staticExpression1.py @@ -51,11 +51,13 @@ else: x = "error!" + class Dummy: DEFINED_FALSE: bool DEFINED_TRUE: bool DEFINED_STR: str + dummy = Dummy() if dummy.DEFINED_TRUE: diff --git a/packages/pyright-internal/src/tests/samples/threePartVersion1.py b/packages/pyright-internal/src/tests/samples/staticExpression2.py similarity index 91% rename from packages/pyright-internal/src/tests/samples/threePartVersion1.py rename to packages/pyright-internal/src/tests/samples/staticExpression2.py index 540685acbb9a..a65ffad906ad 100644 --- a/packages/pyright-internal/src/tests/samples/threePartVersion1.py +++ b/packages/pyright-internal/src/tests/samples/staticExpression2.py @@ -1,5 +1,6 @@ -import sys +# This sample tests a special form of a sys.version_info check. +import sys from datetime import datetime, timezone, timedelta from typing import overload, Optional diff --git a/packages/pyright-internal/src/tests/samples/subscript1.py b/packages/pyright-internal/src/tests/samples/subscript1.py index 99d8507649da..8c031c4da66c 100644 --- a/packages/pyright-internal/src/tests/samples/subscript1.py +++ b/packages/pyright-internal/src/tests/samples/subscript1.py @@ -6,6 +6,7 @@ from collections import OrderedDict, deque from asyncio import Future, Task + # These should generate errors for Python 3.8 and older. def func1( a1: Queue[int], diff --git a/packages/pyright-internal/src/tests/samples/subscript2.py b/packages/pyright-internal/src/tests/samples/subscript2.py index d1ff78ef8fd0..78aa8ff2d83e 100644 --- a/packages/pyright-internal/src/tests/samples/subscript2.py +++ b/packages/pyright-internal/src/tests/samples/subscript2.py @@ -1,12 +1,12 @@ # This sample tests various forms of subscript expressions for # syntax and semantic (type) errors. -from typing import List, TypeVar +from typing import TypeVar _T = TypeVar("_T", list, tuple) -def func1(p1: List[int], p2: _T): +def func1(p1: list[int], p2: _T): a1 = p1[0] reveal_type(a1, expected_text="int") diff --git a/packages/pyright-internal/src/tests/samples/subscript3.py b/packages/pyright-internal/src/tests/samples/subscript3.py index fe221f8aef5c..3d0d2540aa07 100644 --- a/packages/pyright-internal/src/tests/samples/subscript3.py +++ b/packages/pyright-internal/src/tests/samples/subscript3.py @@ -1,7 +1,7 @@ # This sample tests subscript forms specified in PEP 637 - # keyword and unpacked args. -from typing import Any, Tuple, Union, overload +from typing import Any, Union, overload class ClassA: @@ -10,7 +10,7 @@ def __getitem__(self, index: int) -> int: ... @overload - def __getitem__(self, index: Tuple[int, ...]) -> float: + def __getitem__(self, index: tuple[int, ...]) -> float: ... @overload @@ -25,7 +25,7 @@ def __setitem__(self, index: int, value: int) -> None: ... @overload - def __setitem__(self, index: Tuple[int, ...], value: float) -> None: + def __setitem__(self, index: tuple[int, ...], value: float) -> None: ... @overload @@ -93,7 +93,7 @@ def __setitem__(self, index: Any, value: Union[str, float], *, v1: int = 3) -> N class ClassB: - def __getitem__(self, value: Tuple[()], *, v1: int) -> str: + def __getitem__(self, value: tuple[()], *, v1: int) -> str: ... b_obj = ClassB() diff --git a/packages/pyright-internal/src/tests/samples/subscript4.py b/packages/pyright-internal/src/tests/samples/subscript4.py index 01bec6b8a86d..a4b6f734ee4e 100644 --- a/packages/pyright-internal/src/tests/samples/subscript4.py +++ b/packages/pyright-internal/src/tests/samples/subscript4.py @@ -3,8 +3,8 @@ # pyright: strict + def func1(lst: list[tuple[int, int]]): for _ in range(1): lst[-1] = lst[-1][1], lst[-1][0] del lst[-1] - diff --git a/packages/pyright-internal/src/tests/samples/super10.py b/packages/pyright-internal/src/tests/samples/super10.py index 8c790952a351..967908e2de40 100644 --- a/packages/pyright-internal/src/tests/samples/super10.py +++ b/packages/pyright-internal/src/tests/samples/super10.py @@ -1,5 +1,6 @@ # This sample tests that super() calls use Self for binding. + class A: def clone(self): return self diff --git a/packages/pyright-internal/src/tests/samples/super2.py b/packages/pyright-internal/src/tests/samples/super2.py index a9b55640cb60..95835661bddf 100644 --- a/packages/pyright-internal/src/tests/samples/super2.py +++ b/packages/pyright-internal/src/tests/samples/super2.py @@ -1,7 +1,7 @@ # This sample tests the handling of the "super" call when # used with a two-argument form that specifies the "bind to" type. -from typing import Type, TypeVar +from typing import TypeVar T = TypeVar("T", bound="A") @@ -9,7 +9,7 @@ class A: @classmethod - def factory(cls: Type[T]) -> T: + def factory(cls: type[T]) -> T: return cls() diff --git a/packages/pyright-internal/src/tests/samples/super6.py b/packages/pyright-internal/src/tests/samples/super6.py index 34c34612c398..aedafcd661c4 100644 --- a/packages/pyright-internal/src/tests/samples/super6.py +++ b/packages/pyright-internal/src/tests/samples/super6.py @@ -17,25 +17,22 @@ def __new__(cls): reveal_type(f, expected_text="Foo") - class FirstLevelMeta(type): def __new__(cls, name: str, bases, dct): new_class = super().__new__(cls, name, bases, dct) - reveal_type(new_class, expected_text='Self@FirstLevelMeta') + reveal_type(new_class, expected_text="Self@FirstLevelMeta") return new_class class SecondLevelMeta(FirstLevelMeta): def __new__(cls, name: str, bases, dct): new_class = super().__new__(cls, name, bases, dct) - reveal_type(new_class, expected_text='Self@SecondLevelMeta') + reveal_type(new_class, expected_text="Self@SecondLevelMeta") return new_class class ThirdLevelMeta(SecondLevelMeta): def __new__(cls, name: str, bases, dct): new_class = super().__new__(cls, name, bases, dct) - reveal_type(new_class, expected_text='Self@ThirdLevelMeta') + reveal_type(new_class, expected_text="Self@ThirdLevelMeta") return new_class - - diff --git a/packages/pyright-internal/src/tests/samples/totalOrdering1.py b/packages/pyright-internal/src/tests/samples/totalOrdering1.py index 5b4207edb455..8c6882e34803 100644 --- a/packages/pyright-internal/src/tests/samples/totalOrdering1.py +++ b/packages/pyright-internal/src/tests/samples/totalOrdering1.py @@ -20,6 +20,7 @@ def __gt__(self, other: object) -> bool: v5 = a == b v6 = a != b + # This should generate an error because it doesn't declare # any of the required ordering functions. @total_ordering diff --git a/packages/pyright-internal/src/tests/samples/tryExcept1.py b/packages/pyright-internal/src/tests/samples/tryExcept1.py index ca49b13f3e48..7888d4a0f055 100644 --- a/packages/pyright-internal/src/tests/samples/tryExcept1.py +++ b/packages/pyright-internal/src/tests/samples/tryExcept1.py @@ -3,7 +3,6 @@ def func1(): - try: pass except: diff --git a/packages/pyright-internal/src/tests/samples/tryExcept10.py b/packages/pyright-internal/src/tests/samples/tryExcept10.py index 87632cb02b9a..15b474a42df2 100644 --- a/packages/pyright-internal/src/tests/samples/tryExcept10.py +++ b/packages/pyright-internal/src/tests/samples/tryExcept10.py @@ -1,6 +1,7 @@ # This sample tests that type errors within a finally clause are # property detected. + def func1() -> None: file = None try: diff --git a/packages/pyright-internal/src/tests/samples/tryExcept2.py b/packages/pyright-internal/src/tests/samples/tryExcept2.py index cd743740b8d1..6beebf81aed7 100644 --- a/packages/pyright-internal/src/tests/samples/tryExcept2.py +++ b/packages/pyright-internal/src/tests/samples/tryExcept2.py @@ -1,11 +1,11 @@ # This sample tests basic handling of nested finally clauses. -def deallocate(i: int) -> None: +def func1(i: int) -> None: pass -def test(): +def func2(): aaa = 3 try: try: @@ -13,4 +13,4 @@ def test(): finally: pass finally: - deallocate(aaa) + func1(aaa) diff --git a/packages/pyright-internal/src/tests/samples/tryExcept3.py b/packages/pyright-internal/src/tests/samples/tryExcept3.py index 5120e750c7d2..d265387f4406 100644 --- a/packages/pyright-internal/src/tests/samples/tryExcept3.py +++ b/packages/pyright-internal/src/tests/samples/tryExcept3.py @@ -1,9 +1,7 @@ # This sample verifies that the exception type validation # handles the case where the exception type is a Type[X] object. -from typing import Type - -exc: Type[Exception] = Exception +exc: type[Exception] = Exception try: diff --git a/packages/pyright-internal/src/tests/samples/tryExcept8.py b/packages/pyright-internal/src/tests/samples/tryExcept8.py index 3ec4e599efd2..ae755bc0b2fd 100644 --- a/packages/pyright-internal/src/tests/samples/tryExcept8.py +++ b/packages/pyright-internal/src/tests/samples/tryExcept8.py @@ -1,7 +1,7 @@ # This sample tests the detection of inaccessible exception handlers. -from typing import Type, Union +from typing import Union def func1() -> None: @@ -51,7 +51,7 @@ def func5(): pass -def func6(u: Union[Type[Exception], tuple[Type[Exception], ...]]): +def func6(u: Union[type[Exception], tuple[type[Exception], ...]]): try: ... except ValueError as e: @@ -60,7 +60,7 @@ def func6(u: Union[Type[Exception], tuple[Type[Exception], ...]]): ... -def func7(u: Type[Exception]): +def func7(u: type[Exception]): try: ... except ValueError as e: diff --git a/packages/pyright-internal/src/tests/samples/tuples1.py b/packages/pyright-internal/src/tests/samples/tuple1.py similarity index 99% rename from packages/pyright-internal/src/tests/samples/tuples1.py rename to packages/pyright-internal/src/tests/samples/tuple1.py index 10d2182ba1d9..9acc8ec96552 100644 --- a/packages/pyright-internal/src/tests/samples/tuples1.py +++ b/packages/pyright-internal/src/tests/samples/tuple1.py @@ -90,6 +90,7 @@ def func10() -> tuple[int, ...]: func9((2, 3, 4)) func9((2,)) + # Tests for tuple assignments with unpack expressions. def func10_1() -> int: a = (3, 4, 5) diff --git a/packages/pyright-internal/src/tests/samples/tuples10.py b/packages/pyright-internal/src/tests/samples/tuple10.py similarity index 81% rename from packages/pyright-internal/src/tests/samples/tuples10.py rename to packages/pyright-internal/src/tests/samples/tuple10.py index 7bea94fe8b3a..fe2a4234bc3a 100644 --- a/packages/pyright-internal/src/tests/samples/tuples10.py +++ b/packages/pyright-internal/src/tests/samples/tuple10.py @@ -2,7 +2,7 @@ # literals under the appropriate circumstances. -from typing import List, Literal, Tuple +from typing import Literal a1 = (1, 2) @@ -11,11 +11,11 @@ a2 = list((1, 2)) reveal_type(a2, expected_text="list[Literal[1, 2]]") -a3: List[Literal[1]] = list((1,)) +a3: list[Literal[1]] = list((1,)) reveal_type(a3, expected_text="list[Literal[1]]") -def func1(v1: Tuple[Literal[1], ...], v2: Tuple[Literal[1]]): +def func1(v1: tuple[Literal[1], ...], v2: tuple[Literal[1]]): a4 = set(v1) reveal_type(a4, expected_text="set[Literal[1]]") diff --git a/packages/pyright-internal/src/tests/samples/tuple11.py b/packages/pyright-internal/src/tests/samples/tuple11.py new file mode 100644 index 000000000000..6b3540107000 --- /dev/null +++ b/packages/pyright-internal/src/tests/samples/tuple11.py @@ -0,0 +1,19 @@ +# This sample tests the handling of magic methods on +# the tuple class. + + +def func1(t1: tuple[int, ...], t2: tuple[int, ...]): + return t1 >= t2 + + +def func2(t1: tuple[int, ...], t2: tuple[str, int]): + return t1 < t2 + + +def func3(t1: tuple[int, int], t2: tuple[int, ...]): + return t1 > t2 + + +def func4(t1: tuple[int, ...], t2: tuple[str, ...]): + # This should generate an error + return t1 <= t2 diff --git a/packages/pyright-internal/src/tests/samples/tuples12.py b/packages/pyright-internal/src/tests/samples/tuple12.py similarity index 100% rename from packages/pyright-internal/src/tests/samples/tuples12.py rename to packages/pyright-internal/src/tests/samples/tuple12.py diff --git a/packages/pyright-internal/src/tests/samples/tuples13.py b/packages/pyright-internal/src/tests/samples/tuple13.py similarity index 86% rename from packages/pyright-internal/src/tests/samples/tuples13.py rename to packages/pyright-internal/src/tests/samples/tuple13.py index 82da99a43e12..d143285ebc7c 100644 --- a/packages/pyright-internal/src/tests/samples/tuples13.py +++ b/packages/pyright-internal/src/tests/samples/tuple13.py @@ -1,9 +1,7 @@ # This sample tests indexing of tuples with slice expressions. -from typing import Tuple - -def func1(val1: Tuple[int, str, None], val2: Tuple[int, ...]): +def func1(val1: tuple[int, str, None], val2: tuple[int, ...]): x1 = val1[:2] reveal_type(x1, expected_text="tuple[int, str]") diff --git a/packages/pyright-internal/src/tests/samples/tuples15.py b/packages/pyright-internal/src/tests/samples/tuple15.py similarity index 79% rename from packages/pyright-internal/src/tests/samples/tuples15.py rename to packages/pyright-internal/src/tests/samples/tuple15.py index fdaf16000b5f..495ec52cd7c1 100644 --- a/packages/pyright-internal/src/tests/samples/tuples15.py +++ b/packages/pyright-internal/src/tests/samples/tuple15.py @@ -1,18 +1,15 @@ # This sample tests the special-case handling of the __add__ operator # when two tuples of known types are added together. -from typing import Tuple - - v1 = () + () reveal_type(v1, expected_text="tuple[()]") -def func1(a: Tuple[int, int, int], b: Tuple[str, str]): +def func1(a: tuple[int, int, int], b: tuple[str, str]): reveal_type(a + b, expected_text="tuple[int, int, int, str, str]") -def func2(a: Tuple[int, int, int], b: Tuple[str, ...]): +def func2(a: tuple[int, int, int], b: tuple[str, ...]): reveal_type(a + b, expected_text="tuple[int | str, ...]") diff --git a/packages/pyright-internal/src/tests/samples/tuples16.py b/packages/pyright-internal/src/tests/samples/tuple16.py similarity index 60% rename from packages/pyright-internal/src/tests/samples/tuples16.py rename to packages/pyright-internal/src/tests/samples/tuple16.py index ca57eebb05b9..689282893a89 100644 --- a/packages/pyright-internal/src/tests/samples/tuples16.py +++ b/packages/pyright-internal/src/tests/samples/tuple16.py @@ -1,12 +1,9 @@ # This sample tests the handling of bidirectional type inference # for unions of tuples. -from typing import Dict, Tuple, Union - - # The following two unions are the same but declared in different orders. -TupleUnion1 = Union[Tuple[int, str], Tuple[int, str, Dict[str, Union[str, int]]]] -TupleUnion2 = Union[Tuple[int, str, Dict[str, Union[str, int]]], Tuple[int, str]] +TupleUnion1 = tuple[int, str] | tuple[int, str, dict[str, str | int]] +TupleUnion2 = tuple[int, str, dict[str, str | int]] | tuple[int, str] v1: TupleUnion1 = 1, "two", {"hey": "three"} v2: TupleUnion2 = 1, "two", {"hey": "three"} diff --git a/packages/pyright-internal/src/tests/samples/tuples17.py b/packages/pyright-internal/src/tests/samples/tuple17.py similarity index 99% rename from packages/pyright-internal/src/tests/samples/tuples17.py rename to packages/pyright-internal/src/tests/samples/tuple17.py index 366c18a4b3fb..6aa75932859f 100644 --- a/packages/pyright-internal/src/tests/samples/tuples17.py +++ b/packages/pyright-internal/src/tests/samples/tuple17.py @@ -1,6 +1,7 @@ # This sample tests a limiter that prevents infinite recursion # in the tuple inference logic. + def func1(val: int): t = None while True: diff --git a/packages/pyright-internal/src/tests/samples/tuples18.py b/packages/pyright-internal/src/tests/samples/tuple18.py similarity index 100% rename from packages/pyright-internal/src/tests/samples/tuples18.py rename to packages/pyright-internal/src/tests/samples/tuple18.py diff --git a/packages/pyright-internal/src/tests/samples/tuple2.py b/packages/pyright-internal/src/tests/samples/tuple2.py new file mode 100644 index 000000000000..816745776b77 --- /dev/null +++ b/packages/pyright-internal/src/tests/samples/tuple2.py @@ -0,0 +1,20 @@ +# This sample file tests various aspects of type analysis for tuples. + +no_args: tuple = () +zero_length: tuple[()] = () +all_ints1: tuple[int, ...] = () +all_ints2: tuple[int, ...] = (1,) +all_ints3: tuple[int, ...] = (1, 3, 4) + +all_ints1 = all_ints2 +all_ints2 = all_ints3 +all_ints3 = all_ints2 + +# This should generate an error. +bad_ellipsis1: tuple[...] + +# This should generate an error +bad_ellipsis2: tuple[int, int, ...] + +# This should generate an error +bad_ellipsis3: tuple[int, ..., int] diff --git a/packages/pyright-internal/src/tests/samples/tuples3.py b/packages/pyright-internal/src/tests/samples/tuple3.py similarity index 63% rename from packages/pyright-internal/src/tests/samples/tuples3.py rename to packages/pyright-internal/src/tests/samples/tuple3.py index a95e198c89eb..0183e3b3bc40 100644 --- a/packages/pyright-internal/src/tests/samples/tuples3.py +++ b/packages/pyright-internal/src/tests/samples/tuple3.py @@ -1,15 +1,13 @@ # This sample tests the assignment of heterogeneous tuples # to homogeneous tuple types. -from typing import Tuple - -def bar(values: Tuple[str, ...]): +def func1(values: tuple[str, ...]): ... # This should generate an error -bar(("", False)) +func1(("", False)) # This should generate an error -bar((False, "")) +func1((False, "")) diff --git a/packages/pyright-internal/src/tests/samples/tuples4.py b/packages/pyright-internal/src/tests/samples/tuple4.py similarity index 78% rename from packages/pyright-internal/src/tests/samples/tuples4.py rename to packages/pyright-internal/src/tests/samples/tuple4.py index 642113fa8cad..af783ec3d84e 100644 --- a/packages/pyright-internal/src/tests/samples/tuples4.py +++ b/packages/pyright-internal/src/tests/samples/tuple4.py @@ -1,7 +1,7 @@ # This sample tests the translation of a heterogeneous tuple # into an Iterable. -from typing import Iterable, TypeVar, Union +from typing import Iterable, TypeVar _T = TypeVar("_T") @@ -10,7 +10,7 @@ def foo(x: Iterable[_T]) -> Iterable[_T]: return x -def bar(x: Iterable[Union[int, str]]): +def bar(x: Iterable[int | str]): pass diff --git a/packages/pyright-internal/src/tests/samples/tuples5.py b/packages/pyright-internal/src/tests/samples/tuple5.py similarity index 79% rename from packages/pyright-internal/src/tests/samples/tuples5.py rename to packages/pyright-internal/src/tests/samples/tuple5.py index 0ba4a64e5d4e..5f2ef897749c 100644 --- a/packages/pyright-internal/src/tests/samples/tuples5.py +++ b/packages/pyright-internal/src/tests/samples/tuple5.py @@ -1,16 +1,14 @@ # This sample tests the type checker's handling of # empty tuples and assignment to empty tuples. -from typing import Tuple - -a: Tuple[()] = () +a: tuple[()] = () # This should generate an error because the assigned # tuple has one element, but the destination is # expecting zero. -b: Tuple[()] = (1,) +b: tuple[()] = (1,) # This should generate an error because the assigned # tuple has zero elements, but the destination is # expecting two. -c: Tuple[int, str] = () +c: tuple[int, str] = () diff --git a/packages/pyright-internal/src/tests/samples/tuples6.py b/packages/pyright-internal/src/tests/samples/tuple6.py similarity index 91% rename from packages/pyright-internal/src/tests/samples/tuples6.py rename to packages/pyright-internal/src/tests/samples/tuple6.py index 49625f74e8a1..af0e0b42a24c 100644 --- a/packages/pyright-internal/src/tests/samples/tuples6.py +++ b/packages/pyright-internal/src/tests/samples/tuple6.py @@ -1,14 +1,14 @@ # This sample tests tuple parameter matching for # cases where an unpack operator is used in the target. -from typing import Iterable, Tuple, Union +from typing import Iterable a: int b: int c: str d: str e: Iterable[int] -f: Iterable[Union[str, int]] +f: Iterable[str | int] # This should generate an error because an unpack # operator must be within a tuple. @@ -44,7 +44,7 @@ a, b, *e, c, d = 3, 4, 5, "a", "b", "c" -def func1(p1: Tuple[str, ...]): +def func1(p1: tuple[str, ...]): global a, b, c, d c, d = p1 diff --git a/packages/pyright-internal/src/tests/samples/tuples7.py b/packages/pyright-internal/src/tests/samples/tuple7.py similarity index 81% rename from packages/pyright-internal/src/tests/samples/tuples7.py rename to packages/pyright-internal/src/tests/samples/tuple7.py index b3837397bba6..13aa52fec098 100644 --- a/packages/pyright-internal/src/tests/samples/tuples7.py +++ b/packages/pyright-internal/src/tests/samples/tuple7.py @@ -1,8 +1,7 @@ # This sample tests handling of tuples and tracking # of specific types within a tuple. -from typing import Generic, List, Optional, Tuple, TypeVar -from typing_extensions import Self +from typing import Generic, TypeVar, Self _T = TypeVar("_T") @@ -28,15 +27,13 @@ def __new__(cls) -> Self: # This should generate an error because the trailing # comma turns the index value into a tuple. -e = objA[ - 0, -] +e = objA[0,] for aaa in objA: print(aaa) -class ClassB(Tuple[_T, ...]): +class ClassB(tuple[_T, ...]): def __new__(cls) -> Self: ... @@ -54,11 +51,11 @@ def __new__(cls) -> Self: zz2: complex = objB[2] -def func1(lst: Optional[List[str]]) -> None: +def func1(lst: list[str] | None) -> None: for item in lst or (): reveal_type(item, expected_text="str") class X(Generic[_T]): def __init__(self): - self._x: Tuple[_T, ...] = () + self._x: tuple[_T, ...] = () diff --git a/packages/pyright-internal/src/tests/samples/tuples8.py b/packages/pyright-internal/src/tests/samples/tuple8.py similarity index 93% rename from packages/pyright-internal/src/tests/samples/tuples8.py rename to packages/pyright-internal/src/tests/samples/tuple8.py index df84ec6124bf..449b9bb15a65 100644 --- a/packages/pyright-internal/src/tests/samples/tuples8.py +++ b/packages/pyright-internal/src/tests/samples/tuple8.py @@ -1,8 +1,7 @@ # This sample verifies that the "tuple" type is treated # analogously to "Tuple" type. -from typing import Iterable, Tuple, TypeVar -from typing_extensions import Self +from typing import Iterable, TypeVar, Self _T = TypeVar("_T") @@ -90,7 +89,7 @@ def __new__(cls) -> Self: T = TypeVar("T") -def baz(v: Iterable[T]) -> Tuple[T]: +def baz(v: Iterable[T]) -> tuple[T]: ... diff --git a/packages/pyright-internal/src/tests/samples/tuples9.py b/packages/pyright-internal/src/tests/samples/tuple9.py similarity index 74% rename from packages/pyright-internal/src/tests/samples/tuples9.py rename to packages/pyright-internal/src/tests/samples/tuple9.py index b37367fa2645..5b8b5a55abcc 100644 --- a/packages/pyright-internal/src/tests/samples/tuples9.py +++ b/packages/pyright-internal/src/tests/samples/tuple9.py @@ -5,13 +5,10 @@ # pyright: strict -from typing import Tuple - - str_list = ["1", "2", "3"] left, right = tuple(str_list) -check1: Tuple[str, str] = (left, right) +check1: tuple[str, str] = (left, right) # This should generate an error -check2: Tuple[str, int] = (left, right) +check2: tuple[str, int] = (left, right) diff --git a/packages/pyright-internal/src/tests/samples/tupleUnpack1.py b/packages/pyright-internal/src/tests/samples/tupleUnpack1.py index 513cf4d6eaa1..d876691b5209 100644 --- a/packages/pyright-internal/src/tests/samples/tupleUnpack1.py +++ b/packages/pyright-internal/src/tests/samples/tupleUnpack1.py @@ -1,42 +1,42 @@ # This sample tests the handling of Unpack[Tuple[...]] as described # in PEP 646. -from typing import Tuple, Union +from typing import Union from typing_extensions import Unpack -def func1(v1: Tuple[int, Unpack[Tuple[bool, bool]], str]): - reveal_type(v1, expected_text="Tuple[int, bool, bool, str]") +def func1(v1: tuple[int, Unpack[tuple[bool, bool]], str]): + reveal_type(v1, expected_text="tuple[int, bool, bool, str]") # This should generate an error because multiple unpacks. -def func2(v2: Tuple[int, Unpack[Tuple[bool, bool]], str, Unpack[Tuple[bool, bool]]]): +def func2(v2: tuple[int, Unpack[tuple[bool, bool]], str, Unpack[tuple[bool, bool]]]): pass -def func3(v3: Tuple[int, Unpack[Tuple[bool, ...]], str]): - reveal_type(v3, expected_text="Tuple[int, *tuple[bool, ...], str]") +def func3(v3: tuple[int, Unpack[tuple[bool, ...]], str]): + reveal_type(v3, expected_text="tuple[int, *tuple[bool, ...], str]") # This should generate an error because there are multiple unbounded tuples. -def func4(v4: Tuple[Unpack[Tuple[bool, ...]], ...]): +def func4(v4: tuple[Unpack[tuple[bool, ...]], ...]): pass # This should generate an error because there are multiple unbounded tuples. -def func5(v5: Tuple[Unpack[Tuple[Unpack[Tuple[bool, ...]]]], ...]): +def func5(v5: tuple[Unpack[tuple[Unpack[tuple[bool, ...]]]], ...]): pass -def func6(v6: Tuple[Unpack[Tuple[bool]], ...]): - reveal_type(v6, expected_text="Tuple[bool, ...]") +def func6(v6: tuple[Unpack[tuple[bool]], ...]): + reveal_type(v6, expected_text="tuple[bool, ...]") -def func7(v7: Tuple[Unpack[Tuple[bool, Unpack[Tuple[int, float]]]]]): - reveal_type(v7, expected_text="Tuple[bool, int, float]") +def func7(v7: tuple[Unpack[tuple[bool, Unpack[tuple[int, float]]]]]): + reveal_type(v7, expected_text="tuple[bool, int, float]") -def func8(v8: Union[Unpack[Tuple[Unpack[Tuple[bool, Unpack[Tuple[int, ...]]]]]]]): +def func8(v8: Union[Unpack[tuple[Unpack[tuple[bool, Unpack[tuple[int, ...]]]]]]]): reveal_type(v8, expected_text="bool | int") @@ -62,15 +62,16 @@ def func13(t: type): if t is Unpack: ... + def func14( *args: Unpack[tuple[int]], other: str, ) -> None: ... + func14(1, other="hi") # This should generate an error because the second argument # corresponds to a keyword-only parameter. func14(1, "hi") - diff --git a/packages/pyright-internal/src/tests/samples/tuples11.py b/packages/pyright-internal/src/tests/samples/tuples11.py deleted file mode 100644 index 0b870c409348..000000000000 --- a/packages/pyright-internal/src/tests/samples/tuples11.py +++ /dev/null @@ -1,21 +0,0 @@ -# This sample tests the handling of magic methods on -# the tuple class. - -from typing import Tuple - - -def func1(t1: Tuple[int, ...], t2: Tuple[int, ...]): - return t1 >= t2 - - -def func2(t1: Tuple[int, ...], t2: Tuple[str, int]): - return t1 < t2 - - -def func3(t1: Tuple[int, int], t2: Tuple[int, ...]): - return t1 > t2 - - -def func4(t1: Tuple[int, ...], t2: Tuple[str, ...]): - # This should generate an error - return t1 <= t2 diff --git a/packages/pyright-internal/src/tests/samples/tuples2.py b/packages/pyright-internal/src/tests/samples/tuples2.py deleted file mode 100644 index 2d9d2596daa4..000000000000 --- a/packages/pyright-internal/src/tests/samples/tuples2.py +++ /dev/null @@ -1,23 +0,0 @@ -# This sample file tests various aspects of type analysis for tuples. - -from typing import Tuple - - -no_args: Tuple = () -zero_length: Tuple[()] = () -all_ints1: Tuple[int, ...] = () -all_ints2: Tuple[int, ...] = (1,) -all_ints3: Tuple[int, ...] = (1, 3, 4) - -all_ints1 = all_ints2 -all_ints2 = all_ints3 -all_ints3 = all_ints2 - -# This should generate an error. -bad_ellipsis1: Tuple[...] - -# This should generate an error -bad_ellipsis2: Tuple[int, int, ...] - -# This should generate an error -bad_ellipsis3: Tuple[int, ..., int] diff --git a/packages/pyright-internal/src/tests/typeEvaluator1.test.ts b/packages/pyright-internal/src/tests/typeEvaluator1.test.ts index 67107afbddd6..87bb6aa11c22 100644 --- a/packages/pyright-internal/src/tests/typeEvaluator1.test.ts +++ b/packages/pyright-internal/src/tests/typeEvaluator1.test.ts @@ -1221,104 +1221,104 @@ test('Optional2', () => { TestUtils.validateResults(analysisResults, 1); }); -test('Tuples1', () => { - const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuples1.py']); +test('Tuple1', () => { + const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuple1.py']); TestUtils.validateResults(analysisResults, 15); }); -test('Tuples2', () => { - const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuples2.py']); +test('Tuple2', () => { + const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuple2.py']); TestUtils.validateResults(analysisResults, 3); }); -test('Tuples3', () => { - const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuples3.py']); +test('Tuple3', () => { + const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuple3.py']); TestUtils.validateResults(analysisResults, 2); }); -test('Tuples4', () => { - const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuples4.py']); +test('Tuple4', () => { + const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuple4.py']); TestUtils.validateResults(analysisResults, 0); }); -test('Tuples5', () => { - const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuples5.py']); +test('Tuple5', () => { + const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuple5.py']); TestUtils.validateResults(analysisResults, 2); }); -test('Tuples6', () => { - const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuples6.py']); +test('Tuple6', () => { + const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuple6.py']); TestUtils.validateResults(analysisResults, 9); }); -test('Tuples7', () => { - const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuples7.py']); +test('Tuple7', () => { + const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuple7.py']); TestUtils.validateResults(analysisResults, 1); }); -test('Tuples8', () => { - const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuples8.py']); +test('Tuple8', () => { + const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuple8.py']); TestUtils.validateResults(analysisResults, 11); }); -test('Tuples9', () => { - const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuples9.py']); +test('Tuple9', () => { + const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuple9.py']); TestUtils.validateResults(analysisResults, 1); }); -test('Tuples10', () => { - const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuples10.py']); +test('Tuple10', () => { + const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuple10.py']); TestUtils.validateResults(analysisResults, 0); }); -test('Tuples11', () => { - const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuples11.py']); +test('Tuple11', () => { + const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuple11.py']); TestUtils.validateResults(analysisResults, 1); }); -test('Tuples12', () => { - const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuples12.py']); +test('Tuple12', () => { + const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuple12.py']); TestUtils.validateResults(analysisResults, 0); }); -test('Tuples13', () => { - const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuples13.py']); +test('Tuple13', () => { + const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuple13.py']); TestUtils.validateResults(analysisResults, 0); }); -test('Tuples15', () => { - const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuples15.py']); +test('Tuple15', () => { + const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuple15.py']); TestUtils.validateResults(analysisResults, 0); }); -test('Tuples16', () => { - const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuples16.py']); +test('Tuple16', () => { + const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuple16.py']); TestUtils.validateResults(analysisResults, 0); }); -test('Tuples17', () => { - const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuples17.py']); +test('Tuple17', () => { + const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuple17.py']); TestUtils.validateResults(analysisResults, 0); }); -test('Tuples18', () => { - const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuples18.py']); +test('Tuple18', () => { + const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuple18.py']); TestUtils.validateResults(analysisResults, 0); }); @@ -1595,28 +1595,34 @@ test('Dictionary4', () => { TestUtils.validateResults(analysisResults, 0); }); -test('StaticExpressions1', () => { +test('StaticExpression1', () => { const configOptions = new ConfigOptions('.'); configOptions.defaultPythonVersion = PythonVersion.V3_8; configOptions.defaultPythonPlatform = 'windows'; - const analysisResults1 = TestUtils.typeAnalyzeSampleFiles(['staticExpressions1.py'], configOptions); + const analysisResults1 = TestUtils.typeAnalyzeSampleFiles(['staticExpression1.py'], configOptions); TestUtils.validateResults(analysisResults1, 9); configOptions.defaultPythonVersion = PythonVersion.V3_11; configOptions.defaultPythonPlatform = 'Linux'; - const analysisResults2 = TestUtils.typeAnalyzeSampleFiles(['staticExpressions1.py'], configOptions); + const analysisResults2 = TestUtils.typeAnalyzeSampleFiles(['staticExpression1.py'], configOptions); TestUtils.validateResults(analysisResults2, 6); configOptions.defineConstant.set('DEFINED_TRUE', true); configOptions.defineConstant.set('DEFINED_FALSE', false); configOptions.defineConstant.set('DEFINED_STR', 'hi!'); - const analysisResults3 = TestUtils.typeAnalyzeSampleFiles(['staticExpressions1.py'], configOptions); + const analysisResults3 = TestUtils.typeAnalyzeSampleFiles(['staticExpression1.py'], configOptions); TestUtils.validateResults(analysisResults3, 0); }); +test('StaticExpression2', () => { + const analysisResults = TestUtils.typeAnalyzeSampleFiles(['staticExpression2.py']); + + TestUtils.validateResults(analysisResults, 0); +}); + test('SpecialForm1', () => { const analysisResults = TestUtils.typeAnalyzeSampleFiles(['specialForm1.py']); diff --git a/packages/pyright-internal/src/tests/typeEvaluator3.test.ts b/packages/pyright-internal/src/tests/typeEvaluator3.test.ts index b090db46b4f8..5692f2d473ae 100644 --- a/packages/pyright-internal/src/tests/typeEvaluator3.test.ts +++ b/packages/pyright-internal/src/tests/typeEvaluator3.test.ts @@ -460,8 +460,8 @@ test('Comprehension9', () => { TestUtils.validateResults(analysisResults, 0); }); -test('SetComprehension1', () => { - const analysisResults = TestUtils.typeAnalyzeSampleFiles(['setComprehension1.py']); +test('Comprehension10', () => { + const analysisResults = TestUtils.typeAnalyzeSampleFiles(['comprehension10.py']); TestUtils.validateResults(analysisResults, 1); }); diff --git a/packages/pyright-internal/src/tests/typeEvaluator4.test.ts b/packages/pyright-internal/src/tests/typeEvaluator4.test.ts index c7f3e8ff9870..25d8fb31ec60 100644 --- a/packages/pyright-internal/src/tests/typeEvaluator4.test.ts +++ b/packages/pyright-internal/src/tests/typeEvaluator4.test.ts @@ -727,12 +727,6 @@ test('Callable6', () => { TestUtils.validateResults(analysisResults, 9); }); -test('ThreePartVersion1', () => { - const analysisResults = TestUtils.typeAnalyzeSampleFiles(['threePartVersion1.py']); - - TestUtils.validateResults(analysisResults, 0); -}); - test('Generic1', () => { const analysisResults = TestUtils.typeAnalyzeSampleFiles(['generic1.py']);