Skip to content

Commit

Permalink
Finished cleaning up "genericTypesX.py" test files.
Browse files Browse the repository at this point in the history
  • Loading branch information
msfterictraut committed Jun 19, 2023
1 parent 1111f1b commit 899799d
Show file tree
Hide file tree
Showing 94 changed files with 295 additions and 293 deletions.
38 changes: 38 additions & 0 deletions packages/pyright-internal/src/tests/samples/genericType1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This sample tests bidirectional type inference and constraint solving.

m = int(1)
n = float(1.1)
p = "hello"

a = dict(x=m, y=m)
a1: int = a["x"]

b = dict(x=n, y=n)
reveal_type(b, expected_text="dict[str, float]")

# This should generate an error.
b1: int = b["x"]
b2: float = b["x"]

c = dict(x=m, y=n)
reveal_type(c, expected_text="dict[str, float]")

# This should generate an error.
c1: int = c["x"]
c2: float = c["x"]

d = dict(x=p, y=p)
reveal_type(d, expected_text="dict[str, str]")

# This should generate an error.
d1: float = d["x"]
d2: str = d["x"]

e = dict(x=n, y=p)
reveal_type(e, expected_text="dict[str, float | str]")

# This should generate an error.
e1: str = e["x"]
# This should generate an error.
e2: float = e["x"]
e3: float | str = e["x"]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This sample tests a case where Type[X] and X are used within the
# same class declaration.

from typing import Dict, Generic, Type, TypeVar
from typing import Generic, TypeVar
from dataclasses import dataclass, field

K = TypeVar("K")
Expand All @@ -11,7 +11,7 @@
@dataclass
class Registry(Generic[K, V]):
key: K
value: Dict[str, V] = field(default_factory=dict)
value: dict[str, V] = field(default_factory=dict)


class Base:
Expand All @@ -21,7 +21,7 @@ class Base:
BaseType = TypeVar("BaseType", bound=Base)


class BaseTypeRegistry(Registry[Type[BaseType], BaseType]):
class BaseTypeRegistry(Registry[type[BaseType], BaseType]):
pass


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class C(A):
_T_A = TypeVar("_T_A", bound=A)


def testFunc(value: dict[str, _T_A]) -> _T_A:
def func1(value: dict[str, _T_A]) -> _T_A:
return value["a"]


x = testFunc({"b": B(), "c": C()})
x = func1({"b": B(), "c": C()})
reveal_type(x, expected_text="B | C")
35 changes: 0 additions & 35 deletions packages/pyright-internal/src/tests/samples/genericTypes4.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# This sample tests the type variable solving process when a
# callable type is involved.
# This sample tests the constraint solver when a callable type is involved.

# pyright: strict

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This sample tests the special-case handling of Optional[T] within
# a function.
# This sample tests the constraint solver's special-case handling of
# Optional[T] within a function.

from typing import Optional, TypeVar

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This sample tests that Optional types can be matched
# to Type[T] expressions.
# to Type[T] expressions by the constraint solver.

from typing import Callable, Generic, Optional, Type, TypeVar

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This sample tests handling of user-defined type aliases.
# This sample tests handling of type aliases.

from datetime import datetime
from typing import Any, Callable, Generic, TypeVar, Union
Expand Down
Loading

0 comments on commit 899799d

Please sign in to comment.