Skip to content

Commit

Permalink
Changed type printer (the component that renders types into text) to …
Browse files Browse the repository at this point in the history
…use the lowercase `type[x]` instead of `Type[x]`. It has now been four years since PEP 585 deprecated the use of the upper-case version, so most developers should be getting comfortable with the lowercase version at this point.
  • Loading branch information
msfterictraut committed Jun 18, 2023
1 parent e3080b1 commit 52c8cac
Show file tree
Hide file tree
Showing 40 changed files with 71 additions and 71 deletions.
6 changes: 3 additions & 3 deletions packages/pyright-internal/src/analyzer/typePrinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ function printTypeInternal(
recursionTypes,
recursionCount
);
return `Type[${typeString}]`;
return `type[${typeString}]`;
}

return printFunctionType(
Expand Down Expand Up @@ -589,7 +589,7 @@ function printTypeInternal(
if (literalClassStrings.size > 0) {
const literalStrings: string[] = [];
literalClassStrings.forEach((s) => literalStrings.push(s));
dedupedSubtypeStrings.push(`Type[Literal[${literalStrings.join(', ')}]]`);
dedupedSubtypeStrings.push(`type[Literal[${literalStrings.join(', ')}]]`);
}

if (dedupedSubtypeStrings.length === 1) {
Expand Down Expand Up @@ -1188,7 +1188,7 @@ function _printNestedInstantiable(type: Type, textToWrap: string) {
const nestedTypes = (type.instantiableNestingLevel ?? 0) + 1;

for (let nestLevel = 0; nestLevel < nestedTypes; nestLevel++) {
textToWrap = `Type[${textToWrap}]`;
textToWrap = `type[${textToWrap}]`;
}

return textToWrap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ await helper.verifyCompletion('includes', 'markdown', {
{
label: 'AliasT',
kind: Consts.CompletionItemKind.Variable,
documentation: '```python\nAliasT: Type[list[int]]\n```',
documentation: '```python\nAliasT: type[list[int]]\n```',
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ await helper.verifyCompletion('includes', 'markdown', {
label: 'SomeType',
kind: Consts.CompletionItemKind.Variable,
documentation:
"```python\nSomeType: Type[List[int | str]]\n```\n---\nHere's some documentation about SomeType",
"```python\nSomeType: type[List[int | str]]\n```\n---\nHere's some documentation about SomeType",
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//// ''' Alias alone doc string '''

helper.verifyHover('markdown', {
marker1: '```python\n(type alias) A: Type[Foo]\n```\n---\nAlias doc string\n\nOriginal doc string',
marker2: '```python\n(type alias) A: Type[Foo]\n```\n---\nAlias doc string\n\nOriginal doc string',
marker3: '```python\n(type alias) B: Type[Baz]\n```\n---\nAlias alone doc string',
marker1: '```python\n(type alias) A: type[Foo]\n```\n---\nAlias doc string\n\nOriginal doc string',
marker2: '```python\n(type alias) A: type[Foo]\n```\n---\nAlias doc string\n\nOriginal doc string',
marker3: '```python\n(type alias) B: type[Baz]\n```\n---\nAlias alone doc string',
});
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

helper.verifyHover('markdown', {
marker1: '```python\nclass C1(name: str = "hello")\n```\n---\n\\_\\_init\\_\\_ docs',
marker2: '```python\n(type alias) unionType: Type[C1] | Type[C2]\n```',
marker2: '```python\n(type alias) unionType: type[C1] | type[C2]\n```',
marker3: '```python\nclass G(value: int)\n```',
marker4: '```python\nclass G(value: int)\n```',
marker5: '```python\nclass C1(name: str = "hello")\n```\n---\n\\_\\_init\\_\\_ docs',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ helper.verifyHover('markdown', {
marker3: '```python\n(variable) y: Literal[2]\n```\n---\ntest y',
marker4: '```python\n(variable) z: int\n```\n---\ntest z',
marker5:
"```python\n(type alias) SomeType: Type[List[int | str]]\n```\n---\nHere's some documentation about SomeType",
"```python\n(type alias) SomeType: type[List[int | str]]\n```\n---\nHere's some documentation about SomeType",
marker6: '```python\n(variable) x: Literal[123670029844611072]\n```',
});
2 changes: 1 addition & 1 deletion packages/pyright-internal/src/tests/samples/annotated1.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ class B:
Alias2 = str
Alias3 = Alias1[Alias2]

reveal_type(Alias3, expected_text="Type[str]")
reveal_type(Alias3, expected_text="type[str]")
4 changes: 2 additions & 2 deletions packages/pyright-internal/src/tests/samples/classGetItem1.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __class_getitem__(self, args: tuple[int, ...]) -> None:
...


reveal_type(Foo[10, 63], expected_text="Type[Foo]")
reveal_type(Foo[10, 63], expected_text="type[Foo]")


_T = TypeVar("_T")
Expand All @@ -27,4 +27,4 @@ def __class_getitem__(cls, args: tuple[int, ...]) -> None:
...


reveal_type(Bar[int, str], expected_text="Type[Bar[int, str]]")
reveal_type(Bar[int, str], expected_text="type[Bar[int, str]]")
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ def method3() -> None:
reveal_type(s2, expected_text="A")

s3 = A.method2.__self__
reveal_type(s3, expected_text="Type[A]")
reveal_type(s3, expected_text="type[A]")

s3 = A.method2.__self__
reveal_type(s3, expected_text="Type[A]")
reveal_type(s3, expected_text="type[A]")

s4 = A().method2.__self__
reveal_type(s4, expected_text="Type[A]")
reveal_type(s4, expected_text="type[A]")

# This should generate an error because method3 is static.
s5 = A().method3.__self__
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,5 @@ def test_5(a: Any, *args: int, b: Any = ...) -> Any:
val4 = test_5(test_5, b=True)
reveal_type(
val4,
expected_text="Type[list[Overload[(a: Type[(**P(1)@test_5) -> Type[T(1)@test_5]], *, b: Literal[False] | None = ...) -> Type[list[Type[T(1)@test_5]]], (a: T(1)@test_5, *args: int, b: Literal[False] | None = ...) -> Type[list[T(1)@test_5]], (a: T(1)@test_5, *args: int, b: Literal[True] = ...) -> Type[list[T(1)@test_5]], (a: Any, *args: int, b: Any = ...) -> Any]]]",
expected_text="type[list[Overload[(a: type[(**P(1)@test_5) -> type[T(1)@test_5]], *, b: Literal[False] | None = ...) -> type[list[type[T(1)@test_5]]], (a: T(1)@test_5, *args: int, b: Literal[False] | None = ...) -> type[list[T(1)@test_5]], (a: T(1)@test_5, *args: int, b: Literal[True] = ...) -> type[list[T(1)@test_5]], (a: Any, *args: int, b: Any = ...) -> Any]]]",
)
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ def func3(a: None) -> Callable[[type[_T1]], type[_T1]]:


v3 = func3(None)
reveal_type(v3, expected_text="(Type[_T1@func3]) -> Type[_T1@func3]")
reveal_type(v3, expected_text="(type[_T1@func3]) -> type[_T1@func3]")
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def foo(x: int) -> str:
y = func2(x)
z = func2(make_a(foo))

reveal_type(y, expected_text="Type[A[str, (x: int)]]")
reveal_type(z, expected_text="Type[A[str, (x: int)]]")
reveal_type(y, expected_text="type[A[str, (x: int)]]")
reveal_type(z, expected_text="type[A[str, (x: int)]]")


def func4(my_dict: dict[str, str]):
Expand Down
6 changes: 3 additions & 3 deletions packages/pyright-internal/src/tests/samples/genericTypes28.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ class Bar(Foo):
def bar(value: _T1) -> Type[Foo[_T1]]:
baz = Foo(value)
qux = type(baz)
reveal_type(qux, expected_text="Type[Foo[_T1@bar]]")
reveal_type(qux, expected_text="type[Foo[_T1@bar]]")
return qux


d = Bar.get()
reveal_type(d, expected_text="Type[Bar]")
reveal_type(Bar.get(), expected_text="Type[Bar]")
reveal_type(d, expected_text="type[Bar]")
reveal_type(Bar.get(), expected_text="type[Bar]")


def class_constructor(cls: type[_T1]) -> Callable[..., _T1]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ def func7() -> str:
reveal_type(func4({"": 1}), expected_text="int")
reveal_type(func4(func6), expected_text="str")
reveal_type(func4(func7), expected_text="str")
reveal_type(func4(str), expected_text="Type[str]")
reveal_type(func4(str), expected_text="type[str]")
reveal_type(func5(str), expected_text="str")
4 changes: 2 additions & 2 deletions packages/pyright-internal/src/tests/samples/genericTypes46.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ def func7(t: type[_T5]) -> type[_T5]:
val6 = func6(B)
val7 = func7(B)

reveal_type(val6, expected_text="Type[B]")
reveal_type(val7, expected_text="Type[B]")
reveal_type(val6, expected_text="type[B]")
reveal_type(val7, expected_text="type[B]")
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ def __init__(self, thing: T) -> None:

f2 = F[A2](A2())

reveal_type(F[A2], expected_text="Type[F[A]]")
reveal_type(F[A2], expected_text="type[F[A]]")
reveal_type(f2, expected_text="F[A]")
reveal_type(f2.thing, expected_text="A")
4 changes: 2 additions & 2 deletions packages/pyright-internal/src/tests/samples/isinstance1.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def func5(x: int | str | complex):

def func6(x: Type[int] | Type[str] | Type[complex]):
if issubclass(x, (int, str)):
reveal_type(x, expected_text="Type[int] | Type[str]")
reveal_type(x, expected_text="type[int] | type[str]")
else:
reveal_type(x, expected_text="Type[complex]")
reveal_type(x, expected_text="type[complex]")


def func7(x: Optional[Union[int, SomeTypedDict]]):
Expand Down
2 changes: 1 addition & 1 deletion packages/pyright-internal/src/tests/samples/isinstance4.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def get_type_of_object(object: Union[Callable[..., Any], CustomClass]):

def func1(cls: Type[_T1], val: _T1):
if issubclass(cls, CustomClass):
reveal_type(cls, expected_text="Type[CustomClass]*")
reveal_type(cls, expected_text="type[CustomClass]*")
else:
reveal_type(cls, expected_text="Never")

Expand Down
4 changes: 2 additions & 2 deletions packages/pyright-internal/src/tests/samples/isinstance6.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ class Foo:
@classmethod
def bar(cls, other: type):
if issubclass(other, cls):
reveal_type(other, expected_text="Type[Self@Foo]")
reveal_type(other, expected_text="type[Self@Foo]")

if issubclass(other, (int, cls)):
reveal_type(other, expected_text="Type[Self@Foo] | Type[int]")
reveal_type(other, expected_text="type[Self@Foo] | type[int]")

def baz(self, other: object):
if isinstance(other, type(self)):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ class B:
a = A


reveal_type(B.a, expected_text="Type[A]")
reveal_type(B.a, expected_text="type[A]")
reveal_type(B().a, expected_text="A")
4 changes: 2 additions & 2 deletions packages/pyright-internal/src/tests/samples/memberAccess13.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class MockProducer:
produce: Type[Mock] = Mock


reveal_type(MockProducer.produce, expected_text="Type[Mock]")
reveal_type(MockProducer().produce, expected_text="Type[Mock]")
reveal_type(MockProducer.produce, expected_text="type[Mock]")
reveal_type(MockProducer().produce, expected_text="type[Mock]")


reveal_type(MockProducer.produce(), expected_text="Mock")
Expand Down
2 changes: 1 addition & 1 deletion packages/pyright-internal/src/tests/samples/metaclass4.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def do_something(self, p1: str, p2: int):

MyCustomClass = MyMeta("MyCustomClass", (object,), {})

reveal_type(MyCustomClass, expected_text="Type[MyCustomClass]")
reveal_type(MyCustomClass, expected_text="type[MyCustomClass]")


class DerivedCustomClass(MyCustomClass):
Expand Down
4 changes: 2 additions & 2 deletions packages/pyright-internal/src/tests/samples/metaclass5.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class Foo(metaclass=MetaFoo):


def func1(a: Foo):
reveal_type(type(a), expected_text="Type[Foo]")
reveal_type(type("string1"), expected_text="Type[str]")
reveal_type(type(a), expected_text="type[Foo]")
reveal_type(type("string1"), expected_text="type[str]")

reveal_type(type(a) == type("hi"), expected_text="bool")
reveal_type(type("hi") == type("hi"), expected_text="bool")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ def func1():
from enum import Enum


reveal_type(Enum, expected_text="Type[Enum]")
reveal_type(Enum, expected_text="type[Enum]")
6 changes: 3 additions & 3 deletions packages/pyright-internal/src/tests/samples/none2.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# This sample checks that Type[None] is handled correctly.
# This sample checks that type[None] is handled correctly.


from typing import Type


def func1(a: Type[None]) -> Type[str] | Type[None]:
reveal_type(a, expected_text="Type[None]")
reveal_type(a, expected_text="type[None]")

# This should generate an error because None is
# not compatible with Type[None].
Expand All @@ -15,7 +15,7 @@ def func1(a: Type[None]) -> Type[str] | Type[None]:
val1 = func1(type(None))

if val1 is not None:
reveal_type(val1, expected_text="Type[str] | Type[None]")
reveal_type(val1, expected_text="type[str] | type[None]")

# This should generate an error because None isn't
# assignable to Type[None].
Expand Down
4 changes: 2 additions & 2 deletions packages/pyright-internal/src/tests/samples/operators6.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import ctypes

v1 = ctypes.POINTER(ctypes.c_bool) * 3
reveal_type(v1, expected_text="Type[Array[_Pointer[c_bool]]]")
reveal_type(v1, expected_text="type[Array[_Pointer[c_bool]]]")

v2 = 3 * ctypes.POINTER(ctypes.c_bool)
reveal_type(v2, expected_text="Type[Array[_Pointer[c_bool]]]")
reveal_type(v2, expected_text="type[Array[_Pointer[c_bool]]]")
4 changes: 2 additions & 2 deletions packages/pyright-internal/src/tests/samples/properties11.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ class Class3(Class2):
...


reveal_type(Class2.prop1, expected_text="Type[Class2]")
reveal_type(Class3.prop1, expected_text="Type[Class3]")
reveal_type(Class2.prop1, expected_text="type[Class2]")
reveal_type(Class3.prop1, expected_text="type[Class3]")
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@


RecursiveType: TypeAlias = list[Union[str, "RecursiveType"]]
reveal_type(RecursiveType, expected_text="Type[list[str | RecursiveType]]")
reveal_type(RecursiveType, expected_text="type[list[str | RecursiveType]]")
4 changes: 2 additions & 2 deletions packages/pyright-internal/src/tests/samples/self5.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class B(A):


reveal_type(A().one, expected_text="A")
reveal_type(A.two, expected_text="Type[A]")
reveal_type(A.two, expected_text="type[A]")

reveal_type(B().one, expected_text="B")
reveal_type(B.two, expected_text="Type[B]")
reveal_type(B.two, expected_text="type[B]")
2 changes: 1 addition & 1 deletion packages/pyright-internal/src/tests/samples/typeAlias1.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class A:
Value2 = 1


reveal_type(A.Value1, expected_text="Type[Literal[1]]")
reveal_type(A.Value1, expected_text="type[Literal[1]]")
reveal_type(A.Value2, expected_text="int")


Expand Down
2 changes: 1 addition & 1 deletion packages/pyright-internal/src/tests/samples/typeAlias12.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ def fn2(x: List[Alias[V, V]]) -> List[V]:
return x


reveal_type(Alias[int, int], expected_text="Type[int]")
reveal_type(Alias[int, int], expected_text="type[int]")
4 changes: 2 additions & 2 deletions packages/pyright-internal/src/tests/samples/typeAlias13.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class F:
Error = CoroMaybeMethod[DT, [F, E], Any]
reveal_type(
Error,
expected_text="Type[(DT@Error, F, E) -> Coroutine[Any, Any, Any]] | Type[(F, E) -> Coroutine[Any, Any, Any]]",
expected_text="type[(DT@Error, F, E) -> Coroutine[Any, Any, Any]] | type[(F, E) -> Coroutine[Any, Any, Any]]",
)


Expand All @@ -57,5 +57,5 @@ class C:
Something = CoroMaybeMethod[A, [BT, C], Any]
reveal_type(
Something,
expected_text="Type[(A, BT@Something, C) -> Coroutine[Any, Any, Any]] | Type[(BT@Something, C) -> Coroutine[Any, Any, Any]]",
expected_text="type[(A, BT@Something, C) -> Coroutine[Any, Any, Any]] | type[(BT@Something, C) -> Coroutine[Any, Any, Any]]",
)
2 changes: 1 addition & 1 deletion packages/pyright-internal/src/tests/samples/typeAlias15.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ def func1(errs: _MaybeSequence[type[Exception]]):

reveal_type(
_MaybeSequence[type[HttpError]],
expected_text="Type[Type[HttpError]] | Type[Sequence[Type[HttpError]]]",
expected_text="type[type[HttpError]] | type[Sequence[type[HttpError]]]",
)
6 changes: 3 additions & 3 deletions packages/pyright-internal/src/tests/samples/typeAlias4.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def requires_string(a: str):
SimpleNonAlias: Type[int] = int

if sys.version_info > (3, 9):
reveal_type(SimpleAlias, expected_text="Type[int]")
reveal_type(ExplicitAlias, expected_text="Type[int]")
reveal_type(SimpleNonAlias, expected_text="Type[int]")
reveal_type(SimpleAlias, expected_text="type[int]")
reveal_type(ExplicitAlias, expected_text="type[int]")
reveal_type(SimpleNonAlias, expected_text="type[int]")


class ClassB:
Expand Down
4 changes: 2 additions & 2 deletions packages/pyright-internal/src/tests/samples/typeAlias5.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

MyUnion2 = Union[float, datetime]

# This should generate an error because two type arguements are
# This should generate an error because two type arguments are
# expected, but only one was provided.
MyUnion3 = MyUnion1[MyUnion2]

Expand All @@ -24,7 +24,7 @@
MyUnion6 = MyUnion1[Literal[0], Literal["a"]]
reveal_type(
MyUnion6,
expected_text="Type[int] | Type[str] | Type[List[Literal[0]]] | Type[Literal[0, 'a']]",
expected_text="type[int] | type[str] | type[List[Literal[0]]] | type[Literal[0, 'a']]",
)


Expand Down
Loading

0 comments on commit 52c8cac

Please sign in to comment.