diff --git a/crates/ty_ide/src/hover.rs b/crates/ty_ide/src/hover.rs index 2960b9da83..c192b87380 100644 --- a/crates/ty_ide/src/hover.rs +++ b/crates/ty_ide/src/hover.rs @@ -151,14 +151,19 @@ impl fmt::Display for DisplayHoverContent<'_, '_> { Some(TypeVarVariance::Bivariant) => " (bivariant)", None => "", }; + + // Special types like `` + // render poorly with python syntax-highlighting but well as xml + let ty_string = ty + .display_with(self.db, DisplaySettings::default().multiline()) + .to_string(); + let syntax = if ty_string.starts_with('<') { + "xml" + } else { + "python" + }; self.kind - .fenced_code_block( - format!( - "{}{variance}", - ty.display_with(self.db, DisplaySettings::default().multiline()) - ), - "python", - ) + .fenced_code_block(format!("{ty_string}{variance}"), syntax) .fmt(f) } HoverContent::Docstring(docstring) => docstring.render(self.kind).fmt(f), @@ -358,7 +363,7 @@ mod tests { Everyone loves my class!! --------------------------------------------- - ```python + ```xml ``` --- @@ -420,7 +425,7 @@ mod tests { Everyone loves my class!! --------------------------------------------- - ```python + ```xml ``` --- @@ -480,7 +485,7 @@ mod tests { initializes MyClass (perfectly) --------------------------------------------- - ```python + ```xml ``` --- @@ -536,7 +541,7 @@ mod tests { initializes MyClass (perfectly) --------------------------------------------- - ```python + ```xml ``` --- @@ -595,7 +600,7 @@ mod tests { Everyone loves my class!! --------------------------------------------- - ```python + ```xml ``` --- @@ -1680,7 +1685,7 @@ def ab(a: int, *, c: int): Wow this module rocks. --------------------------------------------- - ```python + ```xml ``` --- @@ -2029,7 +2034,7 @@ def function(): assert_snapshot!(test.hover(), @r" --------------------------------------------- - ```python + ```xml ``` --------------------------------------------- @@ -2234,7 +2239,7 @@ def function(): Wow this module rocks. --------------------------------------------- - ```python + ```xml ``` --- @@ -3343,7 +3348,7 @@ def function(): assert_snapshot!(test.hover(), @r" --------------------------------------------- - ```python + ```xml ``` --------------------------------------------- @@ -3385,7 +3390,7 @@ def function(): assert_snapshot!(test.hover(), @r" --------------------------------------------- - ```python + ```xml ``` --------------------------------------------- @@ -3469,7 +3474,7 @@ def function(): assert_snapshot!(test.hover(), @r" --------------------------------------------- - ```python + ```xml ``` --------------------------------------------- @@ -3510,7 +3515,7 @@ def function(): assert_snapshot!(test.hover(), @r" --------------------------------------------- - ```python + ```xml ``` --------------------------------------------- diff --git a/crates/ty_ide/src/inlay_hints.rs b/crates/ty_ide/src/inlay_hints.rs index a958b4451d..6d7d5c9094 100644 --- a/crates/ty_ide/src/inlay_hints.rs +++ b/crates/ty_ide/src/inlay_hints.rs @@ -6216,7 +6216,7 @@ mod tests { assert_snapshot!(test.inlay_hints(), @r#" from typing import Literal - a[: ] = Literal['a', 'b', 'c'] + a[: ] = Literal['a', 'b', 'c'] --------------------------------------------- info[inlay-hint-location]: Inlay Hint Target --> stdlib/typing.pyi:351:1 @@ -6232,7 +6232,7 @@ mod tests { | 2 | from typing import Literal 3 | - 4 | a[: ] = Literal['a', 'b', 'c'] + 4 | a[: ] = Literal['a', 'b', 'c'] | ^^^^^^^ | @@ -6250,7 +6250,7 @@ mod tests { | 2 | from typing import Literal 3 | - 4 | a[: ] = Literal['a', 'b', 'c'] + 4 | a[: ] = Literal['a', 'b', 'c'] | ^^^ | @@ -6268,7 +6268,7 @@ mod tests { | 2 | from typing import Literal 3 | - 4 | a[: ] = Literal['a', 'b', 'c'] + 4 | a[: ] = Literal['a', 'b', 'c'] | ^^^ | @@ -6286,7 +6286,7 @@ mod tests { | 2 | from typing import Literal 3 | - 4 | a[: ] = Literal['a', 'b', 'c'] + 4 | a[: ] = Literal['a', 'b', 'c'] | ^^^ | "#); @@ -6636,7 +6636,7 @@ mod tests { assert_snapshot!(test.inlay_hints(), @r" from typing import Protocol, TypeVar T = TypeVar([name=]'T') - Strange[: ] = Protocol[T] + Strange[: ] = Protocol[T] --------------------------------------------- info[inlay-hint-location]: Inlay Hint Target --> stdlib/typing.pyi:276:13 @@ -6654,7 +6654,7 @@ mod tests { 2 | from typing import Protocol, TypeVar 3 | T = TypeVar([name=]'T') | ^^^^ - 4 | Strange[: ] = Protocol[T] + 4 | Strange[: ] = Protocol[T] | info[inlay-hint-location]: Inlay Hint Target @@ -6671,7 +6671,7 @@ mod tests { | 2 | from typing import Protocol, TypeVar 3 | T = TypeVar([name=]'T') - 4 | Strange[: ] = Protocol[T] + 4 | Strange[: ] = Protocol[T] | ^^^^^^^^^^^^^^^ | @@ -6688,7 +6688,7 @@ mod tests { | 2 | from typing import Protocol, TypeVar 3 | T = TypeVar([name=]'T') - 4 | Strange[: ] = Protocol[T] + 4 | Strange[: ] = Protocol[T] | ^ | "); diff --git a/crates/ty_python_semantic/resources/mdtest/annotations/any.md b/crates/ty_python_semantic/resources/mdtest/annotations/any.md index 1bdc306112..eef66d6b74 100644 --- a/crates/ty_python_semantic/resources/mdtest/annotations/any.md +++ b/crates/ty_python_semantic/resources/mdtest/annotations/any.md @@ -169,13 +169,13 @@ def f(x: Any[int]): `Any` cannot be called (this leads to a `TypeError` at runtime): ```py -Any() # error: [call-non-callable] "Object of type `` is not callable" +Any() # error: [call-non-callable] "Object of type `` is not callable" ``` `Any` also cannot be used as a metaclass (under the hood, this leads to an implicit call to `Any`): ```py -class F(metaclass=Any): ... # error: [invalid-metaclass] "Metaclass type `` is not callable" +class F(metaclass=Any): ... # error: [invalid-metaclass] "Metaclass type `` is not callable" ``` And `Any` cannot be used in `isinstance()` checks: diff --git a/crates/ty_python_semantic/resources/mdtest/annotations/never.md b/crates/ty_python_semantic/resources/mdtest/annotations/never.md index 2cd7845771..62f0968d29 100644 --- a/crates/ty_python_semantic/resources/mdtest/annotations/never.md +++ b/crates/ty_python_semantic/resources/mdtest/annotations/never.md @@ -59,7 +59,7 @@ python-version = "3.11" ```py from typing import Never -reveal_type(Never) # revealed: +reveal_type(Never) # revealed: ``` ### Python 3.10 diff --git a/crates/ty_python_semantic/resources/mdtest/binary/classes.md b/crates/ty_python_semantic/resources/mdtest/binary/classes.md index e0da23bf50..26a7f664b2 100644 --- a/crates/ty_python_semantic/resources/mdtest/binary/classes.md +++ b/crates/ty_python_semantic/resources/mdtest/binary/classes.md @@ -13,7 +13,7 @@ python-version = "3.10" class A: ... class B: ... -reveal_type(A | B) # revealed: +reveal_type(A | B) # revealed: ``` ## Union of two classes (prior to 3.10) @@ -43,14 +43,14 @@ class A: ... class B: ... def _(sub_a: type[A], sub_b: type[B]): - reveal_type(A | sub_b) # revealed: - reveal_type(sub_a | B) # revealed: - reveal_type(sub_a | sub_b) # revealed: + reveal_type(A | sub_b) # revealed: + reveal_type(sub_a | B) # revealed: + reveal_type(sub_a | sub_b) # revealed: class C[T]: ... class D[T]: ... -reveal_type(C | D) # revealed: +reveal_type(C | D) # revealed: -reveal_type(C[int] | D[str]) # revealed: +reveal_type(C[int] | D[str]) # revealed: ``` diff --git a/crates/ty_python_semantic/resources/mdtest/class/super.md b/crates/ty_python_semantic/resources/mdtest/class/super.md index ab96e93ca5..61c24db75a 100644 --- a/crates/ty_python_semantic/resources/mdtest/class/super.md +++ b/crates/ty_python_semantic/resources/mdtest/class/super.md @@ -602,13 +602,13 @@ super(object, object()).__class__ # Not all objects valid in a class's bases list are valid as the first argument to `super()`. # For example, it's valid to inherit from `typing.ChainMap`, but it's not valid as the first argument to `super()`. # -# error: [invalid-super-argument] "`` is not a valid class" +# error: [invalid-super-argument] "`` is not a valid class" reveal_type(super(typing.ChainMap, collections.ChainMap())) # revealed: Unknown # Meanwhile, it's not valid to inherit from unsubscripted `typing.Generic`, # but it *is* valid as the first argument to `super()`. # -# revealed: , > +# revealed: , > reveal_type(super(typing.Generic, typing.SupportsInt)) def _(x: type[typing.Any], y: typing.Any): diff --git a/crates/ty_python_semantic/resources/mdtest/function/return_type.md b/crates/ty_python_semantic/resources/mdtest/function/return_type.md index 81ccb339e7..28bd509e44 100644 --- a/crates/ty_python_semantic/resources/mdtest/function/return_type.md +++ b/crates/ty_python_semantic/resources/mdtest/function/return_type.md @@ -80,7 +80,7 @@ class Foo(Protocol): def f[T](self, v: T) -> T: ... t = (Protocol, int) -reveal_type(t[0]) # revealed: +reveal_type(t[0]) # revealed: class Lorem(t[0]): def f(self) -> int: ... diff --git a/crates/ty_python_semantic/resources/mdtest/implicit_type_aliases.md b/crates/ty_python_semantic/resources/mdtest/implicit_type_aliases.md index ef6f07283f..cd4f6ff26e 100644 --- a/crates/ty_python_semantic/resources/mdtest/implicit_type_aliases.md +++ b/crates/ty_python_semantic/resources/mdtest/implicit_type_aliases.md @@ -77,44 +77,44 @@ IntOrTypeVar = int | T TypeVarOrNone = T | None NoneOrTypeVar = None | T -reveal_type(IntOrStr) # revealed: -reveal_type(IntOrStrOrBytes1) # revealed: -reveal_type(IntOrStrOrBytes2) # revealed: -reveal_type(IntOrStrOrBytes3) # revealed: -reveal_type(IntOrStrOrBytes4) # revealed: -reveal_type(IntOrStrOrBytes5) # revealed: -reveal_type(IntOrStrOrBytes6) # revealed: -reveal_type(BytesOrIntOrStr) # revealed: -reveal_type(IntOrNone) # revealed: -reveal_type(NoneOrInt) # revealed: -reveal_type(IntOrStrOrNone) # revealed: -reveal_type(NoneOrIntOrStr) # revealed: -reveal_type(IntOrAny) # revealed: -reveal_type(AnyOrInt) # revealed: -reveal_type(NoneOrAny) # revealed: -reveal_type(AnyOrNone) # revealed: -reveal_type(NeverOrAny) # revealed: -reveal_type(AnyOrNever) # revealed: -reveal_type(UnknownOrInt) # revealed: -reveal_type(IntOrUnknown) # revealed: -reveal_type(StrOrZero) # revealed: -reveal_type(ZeroOrStr) # revealed: -reveal_type(IntOrLiteralString) # revealed: -reveal_type(LiteralStringOrInt) # revealed: -reveal_type(NoneOrTuple) # revealed: -reveal_type(TupleOrNone) # revealed: -reveal_type(IntOrAnnotated) # revealed: -reveal_type(AnnotatedOrInt) # revealed: -reveal_type(IntOrOptional) # revealed: -reveal_type(OptionalOrInt) # revealed: -reveal_type(IntOrTypeOfStr) # revealed: -reveal_type(TypeOfStrOrInt) # revealed: -reveal_type(IntOrCallable) # revealed: bytes)'> -reveal_type(CallableOrInt) # revealed: bytes) | int'> -reveal_type(TypeVarOrInt) # revealed: -reveal_type(IntOrTypeVar) # revealed: -reveal_type(TypeVarOrNone) # revealed: -reveal_type(NoneOrTypeVar) # revealed: +reveal_type(IntOrStr) # revealed: +reveal_type(IntOrStrOrBytes1) # revealed: +reveal_type(IntOrStrOrBytes2) # revealed: +reveal_type(IntOrStrOrBytes3) # revealed: +reveal_type(IntOrStrOrBytes4) # revealed: +reveal_type(IntOrStrOrBytes5) # revealed: +reveal_type(IntOrStrOrBytes6) # revealed: +reveal_type(BytesOrIntOrStr) # revealed: +reveal_type(IntOrNone) # revealed: +reveal_type(NoneOrInt) # revealed: +reveal_type(IntOrStrOrNone) # revealed: +reveal_type(NoneOrIntOrStr) # revealed: +reveal_type(IntOrAny) # revealed: +reveal_type(AnyOrInt) # revealed: +reveal_type(NoneOrAny) # revealed: +reveal_type(AnyOrNone) # revealed: +reveal_type(NeverOrAny) # revealed: +reveal_type(AnyOrNever) # revealed: +reveal_type(UnknownOrInt) # revealed: +reveal_type(IntOrUnknown) # revealed: +reveal_type(StrOrZero) # revealed: +reveal_type(ZeroOrStr) # revealed: +reveal_type(IntOrLiteralString) # revealed: +reveal_type(LiteralStringOrInt) # revealed: +reveal_type(NoneOrTuple) # revealed: +reveal_type(TupleOrNone) # revealed: +reveal_type(IntOrAnnotated) # revealed: +reveal_type(AnnotatedOrInt) # revealed: +reveal_type(IntOrOptional) # revealed: +reveal_type(OptionalOrInt) # revealed: +reveal_type(IntOrTypeOfStr) # revealed: +reveal_type(TypeOfStrOrInt) # revealed: +reveal_type(IntOrCallable) # revealed: bytes)'> +reveal_type(CallableOrInt) # revealed: bytes) | int'> +reveal_type(TypeVarOrInt) # revealed: +reveal_type(IntOrTypeVar) # revealed: +reveal_type(TypeVarOrNone) # revealed: +reveal_type(NoneOrTypeVar) # revealed: def _( int_or_str: IntOrStr, @@ -295,7 +295,7 @@ X = Foo | Bar # In an ideal world, perhaps we would respect `Meta.__or__` here and reveal `str`? # But we still need to record what the elements are, since (according to the typing spec) # `X` is still a valid type alias -reveal_type(X) # revealed: +reveal_type(X) # revealed: def f(obj: X): reveal_type(obj) # revealed: Foo | Bar @@ -391,17 +391,17 @@ MyOptional = T | None reveal_type(MyList) # revealed: reveal_type(MyDict) # revealed: -reveal_type(MyType) # revealed: +reveal_type(MyType) # revealed: reveal_type(IntAndType) # revealed: reveal_type(Pair) # revealed: reveal_type(Sum) # revealed: -reveal_type(ListOrTuple) # revealed: -# revealed: +reveal_type(ListOrTuple) # revealed: +# revealed: reveal_type(ListOrTupleLegacy) -reveal_type(MyCallable) # revealed: T@MyCallable'> -reveal_type(AnnotatedType) # revealed: ]'> +reveal_type(MyCallable) # revealed: T@MyCallable'> +reveal_type(AnnotatedType) # revealed: ]'> reveal_type(TransparentAlias) # revealed: TypeVar -reveal_type(MyOptional) # revealed: +reveal_type(MyOptional) # revealed: def _( list_of_ints: MyList[int], @@ -457,13 +457,13 @@ AnnotatedInt = AnnotatedType[int] SubclassOfInt = MyType[int] CallableIntToStr = MyCallable[[int], str] -reveal_type(IntsOrNone) # revealed: -reveal_type(IntsOrStrs) # revealed: +reveal_type(IntsOrNone) # revealed: +reveal_type(IntsOrStrs) # revealed: reveal_type(ListOfPairs) # revealed: -reveal_type(ListOrTupleOfInts) # revealed: -reveal_type(AnnotatedInt) # revealed: ]'> -reveal_type(SubclassOfInt) # revealed: -reveal_type(CallableIntToStr) # revealed: str'> +reveal_type(ListOrTupleOfInts) # revealed: +reveal_type(AnnotatedInt) # revealed: ]'> +reveal_type(SubclassOfInt) # revealed: +reveal_type(CallableIntToStr) # revealed: str'> def _( ints_or_none: IntsOrNone, @@ -495,8 +495,8 @@ MyOtherType = MyType[T] TypeOrList = MyType[B] | MyList[B] reveal_type(MyOtherList) # revealed: -reveal_type(MyOtherType) # revealed: -reveal_type(TypeOrList) # revealed: +reveal_type(MyOtherType) # revealed: +reveal_type(TypeOrList) # revealed: def _( list_of_ints: MyOtherList[int], @@ -730,7 +730,7 @@ def _(doubly_specialized: DictInt[int]): Union = list[str] | list[int] -# error: [non-subscriptable] "Cannot subscript non-generic type: `` is already specialized" +# error: [non-subscriptable] "Cannot subscript non-generic type: `` is already specialized" def _(doubly_specialized: Union[int]): reveal_type(doubly_specialized) # revealed: Unknown @@ -974,7 +974,7 @@ from typing import Optional MyOptionalInt = Optional[int] -reveal_type(MyOptionalInt) # revealed: +reveal_type(MyOptionalInt) # revealed: def _(optional_int: MyOptionalInt): reveal_type(optional_int) # revealed: int | None @@ -1007,9 +1007,9 @@ MyLiteralString = LiteralString MyNoReturn = NoReturn MyNever = Never -reveal_type(MyLiteralString) # revealed: -reveal_type(MyNoReturn) # revealed: -reveal_type(MyNever) # revealed: +reveal_type(MyLiteralString) # revealed: +reveal_type(MyNoReturn) # revealed: +reveal_type(MyNever) # revealed: def _( ls: MyLiteralString, @@ -1062,8 +1062,8 @@ from typing import Union IntOrStr = Union[int, str] IntOrStrOrBytes = Union[int, Union[str, bytes]] -reveal_type(IntOrStr) # revealed: -reveal_type(IntOrStrOrBytes) # revealed: +reveal_type(IntOrStr) # revealed: +reveal_type(IntOrStrOrBytes) # revealed: def _( int_or_str: IntOrStr, @@ -1091,7 +1091,7 @@ An empty `typing.Union` leads to a `TypeError` at runtime, so we emit an error. # error: [invalid-type-form] "`typing.Union` requires at least one type argument" EmptyUnion = Union[()] -reveal_type(EmptyUnion) # revealed: +reveal_type(EmptyUnion) # revealed: def _(empty: EmptyUnion): reveal_type(empty) # revealed: Never @@ -1136,14 +1136,14 @@ SubclassOfG = type[G] SubclassOfGInt = type[G[int]] SubclassOfP = type[P] -reveal_type(SubclassOfA) # revealed: -reveal_type(SubclassOfAny) # revealed: -reveal_type(SubclassOfAOrB1) # revealed: -reveal_type(SubclassOfAOrB2) # revealed: -reveal_type(SubclassOfAOrB3) # revealed: -reveal_type(SubclassOfG) # revealed: -reveal_type(SubclassOfGInt) # revealed: -reveal_type(SubclassOfP) # revealed: +reveal_type(SubclassOfA) # revealed: +reveal_type(SubclassOfAny) # revealed: +reveal_type(SubclassOfAOrB1) # revealed: +reveal_type(SubclassOfAOrB2) # revealed: +reveal_type(SubclassOfAOrB3) # revealed: +reveal_type(SubclassOfG) # revealed: +reveal_type(SubclassOfGInt) # revealed: +reveal_type(SubclassOfP) # revealed: def _( subclass_of_a: SubclassOfA, @@ -1224,14 +1224,14 @@ SubclassOfG = Type[G] SubclassOfGInt = Type[G[int]] SubclassOfP = Type[P] -reveal_type(SubclassOfA) # revealed: -reveal_type(SubclassOfAny) # revealed: -reveal_type(SubclassOfAOrB1) # revealed: -reveal_type(SubclassOfAOrB2) # revealed: -reveal_type(SubclassOfAOrB3) # revealed: -reveal_type(SubclassOfG) # revealed: -reveal_type(SubclassOfGInt) # revealed: -reveal_type(SubclassOfP) # revealed: +reveal_type(SubclassOfA) # revealed: +reveal_type(SubclassOfAny) # revealed: +reveal_type(SubclassOfAOrB1) # revealed: +reveal_type(SubclassOfAOrB2) # revealed: +reveal_type(SubclassOfAOrB3) # revealed: +reveal_type(SubclassOfG) # revealed: +reveal_type(SubclassOfGInt) # revealed: +reveal_type(SubclassOfP) # revealed: def _( subclass_of_a: SubclassOfA, @@ -1346,25 +1346,25 @@ DefaultDictOrNone = DefaultDict[str, int] | None DequeOrNone = Deque[str] | None OrderedDictOrNone = OrderedDict[str, int] | None -reveal_type(NoneOrList) # revealed: -reveal_type(NoneOrSet) # revealed: -reveal_type(NoneOrDict) # revealed: -reveal_type(NoneOrFrozenSet) # revealed: -reveal_type(NoneOrChainMap) # revealed: -reveal_type(NoneOrCounter) # revealed: -reveal_type(NoneOrDefaultDict) # revealed: -reveal_type(NoneOrDeque) # revealed: -reveal_type(NoneOrOrderedDict) # revealed: +reveal_type(NoneOrList) # revealed: +reveal_type(NoneOrSet) # revealed: +reveal_type(NoneOrDict) # revealed: +reveal_type(NoneOrFrozenSet) # revealed: +reveal_type(NoneOrChainMap) # revealed: +reveal_type(NoneOrCounter) # revealed: +reveal_type(NoneOrDefaultDict) # revealed: +reveal_type(NoneOrDeque) # revealed: +reveal_type(NoneOrOrderedDict) # revealed: -reveal_type(ListOrNone) # revealed: -reveal_type(SetOrNone) # revealed: -reveal_type(DictOrNone) # revealed: -reveal_type(FrozenSetOrNone) # revealed: -reveal_type(ChainMapOrNone) # revealed: -reveal_type(CounterOrNone) # revealed: -reveal_type(DefaultDictOrNone) # revealed: -reveal_type(DequeOrNone) # revealed: -reveal_type(OrderedDictOrNone) # revealed: +reveal_type(ListOrNone) # revealed: +reveal_type(SetOrNone) # revealed: +reveal_type(DictOrNone) # revealed: +reveal_type(FrozenSetOrNone) # revealed: +reveal_type(ChainMapOrNone) # revealed: +reveal_type(CounterOrNone) # revealed: +reveal_type(DefaultDictOrNone) # revealed: +reveal_type(DequeOrNone) # revealed: +reveal_type(OrderedDictOrNone) # revealed: def _( none_or_list: NoneOrList, @@ -1457,9 +1457,9 @@ CallableNoArgs = Callable[[], None] BasicCallable = Callable[[int, str], bytes] GradualCallable = Callable[..., str] -reveal_type(CallableNoArgs) # revealed: None'> -reveal_type(BasicCallable) # revealed: bytes'> -reveal_type(GradualCallable) # revealed: str'> +reveal_type(CallableNoArgs) # revealed: None'> +reveal_type(BasicCallable) # revealed: bytes'> +reveal_type(GradualCallable) # revealed: str'> def _( callable_no_args: CallableNoArgs, @@ -1491,8 +1491,8 @@ InvalidCallable1 = Callable[[int]] # error: [invalid-type-form] "The first argument to `Callable` must be either a list of types, ParamSpec, Concatenate, or `...`" InvalidCallable2 = Callable[int, str] -reveal_type(InvalidCallable1) # revealed: Unknown'> -reveal_type(InvalidCallable2) # revealed: Unknown'> +reveal_type(InvalidCallable1) # revealed: Unknown'> +reveal_type(InvalidCallable2) # revealed: Unknown'> def _(invalid_callable1: InvalidCallable1, invalid_callable2: InvalidCallable2): reveal_type(invalid_callable1) # revealed: (...) -> Unknown diff --git a/crates/ty_python_semantic/resources/mdtest/import/conventions.md b/crates/ty_python_semantic/resources/mdtest/import/conventions.md index 28ea0b4bc2..d2ec8320d5 100644 --- a/crates/ty_python_semantic/resources/mdtest/import/conventions.md +++ b/crates/ty_python_semantic/resources/mdtest/import/conventions.md @@ -53,8 +53,8 @@ in `import os.path as os.path` the `os.path` is not a valid identifier. ```py from b import Any, Literal, foo -reveal_type(Any) # revealed: -reveal_type(Literal) # revealed: +reveal_type(Any) # revealed: +reveal_type(Literal) # revealed: reveal_type(foo) # revealed: ``` @@ -132,7 +132,7 @@ reveal_type(Any) # revealed: Unknown ```pyi from typing import Any -reveal_type(Any) # revealed: +reveal_type(Any) # revealed: ``` ## Nested mixed re-export and not @@ -169,7 +169,7 @@ reveal_type(Any) # revealed: Unknown ```pyi from typing import Any -reveal_type(Any) # revealed: +reveal_type(Any) # revealed: ``` ## Exported as different name diff --git a/crates/ty_python_semantic/resources/mdtest/import/star.md b/crates/ty_python_semantic/resources/mdtest/import/star.md index a60c0062b1..72c2a97e49 100644 --- a/crates/ty_python_semantic/resources/mdtest/import/star.md +++ b/crates/ty_python_semantic/resources/mdtest/import/star.md @@ -1437,7 +1437,7 @@ are present due to `*` imports. import collections.abc reveal_type(collections.abc.Sequence) # revealed: -reveal_type(collections.abc.Callable) # revealed: +reveal_type(collections.abc.Callable) # revealed: reveal_type(collections.abc.Set) # revealed: ``` diff --git a/crates/ty_python_semantic/resources/mdtest/mro.md b/crates/ty_python_semantic/resources/mdtest/mro.md index da57d7f9a7..72e2360269 100644 --- a/crates/ty_python_semantic/resources/mdtest/mro.md +++ b/crates/ty_python_semantic/resources/mdtest/mro.md @@ -301,7 +301,7 @@ class B: ... EitherOr = A | B -# error: [invalid-base] "Invalid class base with type ``" +# error: [invalid-base] "Invalid class base with type ``" class Foo(EitherOr): ... ``` diff --git a/crates/ty_python_semantic/resources/mdtest/narrow/isinstance.md b/crates/ty_python_semantic/resources/mdtest/narrow/isinstance.md index 68562e06ad..4a78fd8982 100644 --- a/crates/ty_python_semantic/resources/mdtest/narrow/isinstance.md +++ b/crates/ty_python_semantic/resources/mdtest/narrow/isinstance.md @@ -156,7 +156,7 @@ from typing import Union IntOrStr = Union[int, str] -reveal_type(IntOrStr) # revealed: +reveal_type(IntOrStr) # revealed: def _(x: int | str | bytes | memoryview | range): if isinstance(x, IntOrStr): diff --git a/crates/ty_python_semantic/resources/mdtest/narrow/issubclass.md b/crates/ty_python_semantic/resources/mdtest/narrow/issubclass.md index 6c45c19ef2..d07dee6a22 100644 --- a/crates/ty_python_semantic/resources/mdtest/narrow/issubclass.md +++ b/crates/ty_python_semantic/resources/mdtest/narrow/issubclass.md @@ -209,7 +209,7 @@ from typing import Union IntOrStr = Union[int, str] -reveal_type(IntOrStr) # revealed: +reveal_type(IntOrStr) # revealed: def f(x: type[int | str | bytes | range]): if issubclass(x, IntOrStr): diff --git a/crates/ty_python_semantic/resources/mdtest/pep613_type_aliases.md b/crates/ty_python_semantic/resources/mdtest/pep613_type_aliases.md index 69f92dda94..29b13ee4b3 100644 --- a/crates/ty_python_semantic/resources/mdtest/pep613_type_aliases.md +++ b/crates/ty_python_semantic/resources/mdtest/pep613_type_aliases.md @@ -113,7 +113,7 @@ MyList: TypeAlias = list[T] ListOrSet: TypeAlias = list[T] | set[T] reveal_type(MyList) # revealed: -reveal_type(ListOrSet) # revealed: +reveal_type(ListOrSet) # revealed: def _(list_of_int: MyList[int], list_or_set_of_str: ListOrSet[str]): reveal_type(list_of_int) # revealed: list[int] @@ -293,7 +293,7 @@ def _(rec: RecursiveHomogeneousTuple): reveal_type(rec) # revealed: tuple[Divergent, ...] ClassInfo: TypeAlias = type | UnionType | tuple["ClassInfo", ...] -reveal_type(ClassInfo) # revealed: +reveal_type(ClassInfo) # revealed: def my_isinstance(obj: object, classinfo: ClassInfo) -> bool: # TODO should be `type | UnionType | tuple[ClassInfo, ...]` diff --git a/crates/ty_python_semantic/resources/mdtest/snapshots/isinstance.md_-_Narrowing_for_`isins…_-_`classinfo`_is_an_in…_(eeef56c0ef87a30b).snap b/crates/ty_python_semantic/resources/mdtest/snapshots/isinstance.md_-_Narrowing_for_`isins…_-_`classinfo`_is_an_in…_(eeef56c0ef87a30b).snap index 195610b255..9258e5b40c 100644 --- a/crates/ty_python_semantic/resources/mdtest/snapshots/isinstance.md_-_Narrowing_for_`isins…_-_`classinfo`_is_an_in…_(eeef56c0ef87a30b).snap +++ b/crates/ty_python_semantic/resources/mdtest/snapshots/isinstance.md_-_Narrowing_for_`isins…_-_`classinfo`_is_an_in…_(eeef56c0ef87a30b).snap @@ -63,7 +63,7 @@ error[invalid-argument-type]: Invalid second argument to `isinstance` 10 | # error: [invalid-argument-type] | info: A `UnionType` instance can only be used as the second argument to `isinstance` if all elements are class objects -info: Elements `` and `` in the union are not class objects +info: Elements `` and `` in the union are not class objects info: rule `invalid-argument-type` is enabled by default ``` @@ -82,7 +82,7 @@ error[invalid-argument-type]: Invalid second argument to `isinstance` 13 | else: | info: A `UnionType` instance can only be used as the second argument to `isinstance` if all elements are class objects -info: Element `` in the union, and 2 more elements, are not class objects +info: Element `` in the union, and 2 more elements, are not class objects info: rule `invalid-argument-type` is enabled by default ``` diff --git a/crates/ty_python_semantic/resources/mdtest/snapshots/mro.md_-_Method_Resolution_Or…_-_Unresolvable_MROs_in…_(e2b355c09a967862).snap b/crates/ty_python_semantic/resources/mdtest/snapshots/mro.md_-_Method_Resolution_Or…_-_Unresolvable_MROs_in…_(e2b355c09a967862).snap index 42e41b6e87..f460099a95 100644 --- a/crates/ty_python_semantic/resources/mdtest/snapshots/mro.md_-_Method_Resolution_Or…_-_Unresolvable_MROs_in…_(e2b355c09a967862).snap +++ b/crates/ty_python_semantic/resources/mdtest/snapshots/mro.md_-_Method_Resolution_Or…_-_Unresolvable_MROs_in…_(e2b355c09a967862).snap @@ -24,7 +24,7 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/mro.md # Diagnostics ``` -error[inconsistent-mro]: Cannot create a consistent method resolution order (MRO) for class `Baz` with bases list `[, , ]` +error[inconsistent-mro]: Cannot create a consistent method resolution order (MRO) for class `Baz` with bases list `[, , ]` --> src/mdtest_snippet.py:7:1 | 5 | class Foo(Protocol): ... diff --git a/crates/ty_python_semantic/resources/mdtest/snapshots/protocols.md_-_Protocols_-_Calls_to_protocol_cl…_(288988036f34ddcf).snap b/crates/ty_python_semantic/resources/mdtest/snapshots/protocols.md_-_Protocols_-_Calls_to_protocol_cl…_(288988036f34ddcf).snap index 57bedf5797..60ff7043ab 100644 --- a/crates/ty_python_semantic/resources/mdtest/snapshots/protocols.md_-_Protocols_-_Calls_to_protocol_cl…_(288988036f34ddcf).snap +++ b/crates/ty_python_semantic/resources/mdtest/snapshots/protocols.md_-_Protocols_-_Calls_to_protocol_cl…_(288988036f34ddcf).snap @@ -42,7 +42,7 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/protocols.md # Diagnostics ``` -error[call-non-callable]: Object of type `` is not callable +error[call-non-callable]: Object of type `` is not callable --> src/mdtest_snippet.py:4:13 | 3 | # error: [call-non-callable] diff --git a/crates/ty_python_semantic/src/types/display.rs b/crates/ty_python_semantic/src/types/display.rs index 790fcc404f..885c9cb7f0 100644 --- a/crates/ty_python_semantic/src/types/display.rs +++ b/crates/ty_python_semantic/src/types/display.rs @@ -709,7 +709,7 @@ impl<'db> FmtDetailed<'db> for DisplayRepresentation<'db> { }, Type::SpecialForm(special_form) => { f.set_invalid_syntax(); - write!(f.with_type(self.ty), "") + write!(f.with_type(self.ty), "") } Type::KnownInstance(known_instance) => known_instance .display_with(self.db, self.settings.clone()) @@ -2334,7 +2334,7 @@ impl<'db> FmtDetailed<'db> for DisplayKnownInstanceRepr<'db> { match self.known_instance { KnownInstanceType::SubscriptedProtocol(generic_context) => { f.set_invalid_syntax(); - f.write_str(" FmtDetailed<'db> for DisplayKnownInstanceRepr<'db> { } KnownInstanceType::SubscriptedGeneric(generic_context) => { f.set_invalid_syntax(); - f.write_str(" FmtDetailed<'db> for DisplayKnownInstanceRepr<'db> { f.write_char('<')?; f.with_type(KnownClass::UnionType.to_class_literal(self.db)) .write_str("types.UnionType")?; - f.write_str(" special form")?; + f.write_str(" special-form")?; if let Ok(ty) = union.union_type(self.db) { f.write_str(" '")?; ty.display(self.db).fmt_detailed(f)?; @@ -2408,13 +2408,13 @@ impl<'db> FmtDetailed<'db> for DisplayKnownInstanceRepr<'db> { } KnownInstanceType::Literal(inner) => { f.set_invalid_syntax(); - f.write_str("") } KnownInstanceType::Annotated(inner) => { f.set_invalid_syntax(); - f.write_str(" FmtDetailed<'db> for DisplayKnownInstanceRepr<'db> { f.write_char('<')?; f.with_type(Type::SpecialForm(SpecialFormType::Callable)) .write_str("typing.Callable")?; - f.write_str(" special form '")?; + f.write_str(" special-form '")?; callable.display(self.db).fmt_detailed(f)?; f.write_str("'>") } KnownInstanceType::TypeGenericAlias(inner) => { f.set_invalid_syntax(); - f.write_str("