mirror of https://github.com/astral-sh/ruff
[ty] highlight special type syntax in hovers as xml (#22005)
## Summary These types look better rendered as XML than python ## Test Plan <img width="532" height="299" alt="Screenshot 2025-12-16 at 8 40 56 AM" src="https://github.com/user-attachments/assets/42d9abfa-3f4a-44ba-b6b4-6700ab06832d" />
This commit is contained in:
parent
0f373603eb
commit
83168a1bb1
|
|
@ -151,14 +151,19 @@ impl fmt::Display for DisplayHoverContent<'_, '_> {
|
||||||
Some(TypeVarVariance::Bivariant) => " (bivariant)",
|
Some(TypeVarVariance::Bivariant) => " (bivariant)",
|
||||||
None => "",
|
None => "",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Special types like `<special-form of whatever 'blahblah' with 'florps'>`
|
||||||
|
// 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
|
self.kind
|
||||||
.fenced_code_block(
|
.fenced_code_block(format!("{ty_string}{variance}"), syntax)
|
||||||
format!(
|
|
||||||
"{}{variance}",
|
|
||||||
ty.display_with(self.db, DisplaySettings::default().multiline())
|
|
||||||
),
|
|
||||||
"python",
|
|
||||||
)
|
|
||||||
.fmt(f)
|
.fmt(f)
|
||||||
}
|
}
|
||||||
HoverContent::Docstring(docstring) => docstring.render(self.kind).fmt(f),
|
HoverContent::Docstring(docstring) => docstring.render(self.kind).fmt(f),
|
||||||
|
|
@ -358,7 +363,7 @@ mod tests {
|
||||||
Everyone loves my class!!
|
Everyone loves my class!!
|
||||||
|
|
||||||
---------------------------------------------
|
---------------------------------------------
|
||||||
```python
|
```xml
|
||||||
<class 'MyClass'>
|
<class 'MyClass'>
|
||||||
```
|
```
|
||||||
---
|
---
|
||||||
|
|
@ -420,7 +425,7 @@ mod tests {
|
||||||
Everyone loves my class!!
|
Everyone loves my class!!
|
||||||
|
|
||||||
---------------------------------------------
|
---------------------------------------------
|
||||||
```python
|
```xml
|
||||||
<class 'MyClass'>
|
<class 'MyClass'>
|
||||||
```
|
```
|
||||||
---
|
---
|
||||||
|
|
@ -480,7 +485,7 @@ mod tests {
|
||||||
initializes MyClass (perfectly)
|
initializes MyClass (perfectly)
|
||||||
|
|
||||||
---------------------------------------------
|
---------------------------------------------
|
||||||
```python
|
```xml
|
||||||
<class 'MyClass'>
|
<class 'MyClass'>
|
||||||
```
|
```
|
||||||
---
|
---
|
||||||
|
|
@ -536,7 +541,7 @@ mod tests {
|
||||||
initializes MyClass (perfectly)
|
initializes MyClass (perfectly)
|
||||||
|
|
||||||
---------------------------------------------
|
---------------------------------------------
|
||||||
```python
|
```xml
|
||||||
<class 'MyClass'>
|
<class 'MyClass'>
|
||||||
```
|
```
|
||||||
---
|
---
|
||||||
|
|
@ -595,7 +600,7 @@ mod tests {
|
||||||
Everyone loves my class!!
|
Everyone loves my class!!
|
||||||
|
|
||||||
---------------------------------------------
|
---------------------------------------------
|
||||||
```python
|
```xml
|
||||||
<class 'MyClass'>
|
<class 'MyClass'>
|
||||||
```
|
```
|
||||||
---
|
---
|
||||||
|
|
@ -1680,7 +1685,7 @@ def ab(a: int, *, c: int):
|
||||||
Wow this module rocks.
|
Wow this module rocks.
|
||||||
|
|
||||||
---------------------------------------------
|
---------------------------------------------
|
||||||
```python
|
```xml
|
||||||
<module 'lib'>
|
<module 'lib'>
|
||||||
```
|
```
|
||||||
---
|
---
|
||||||
|
|
@ -2029,7 +2034,7 @@ def function():
|
||||||
assert_snapshot!(test.hover(), @r"
|
assert_snapshot!(test.hover(), @r"
|
||||||
<class 'Click'>
|
<class 'Click'>
|
||||||
---------------------------------------------
|
---------------------------------------------
|
||||||
```python
|
```xml
|
||||||
<class 'Click'>
|
<class 'Click'>
|
||||||
```
|
```
|
||||||
---------------------------------------------
|
---------------------------------------------
|
||||||
|
|
@ -2234,7 +2239,7 @@ def function():
|
||||||
Wow this module rocks.
|
Wow this module rocks.
|
||||||
|
|
||||||
---------------------------------------------
|
---------------------------------------------
|
||||||
```python
|
```xml
|
||||||
<module 'lib'>
|
<module 'lib'>
|
||||||
```
|
```
|
||||||
---
|
---
|
||||||
|
|
@ -3343,7 +3348,7 @@ def function():
|
||||||
assert_snapshot!(test.hover(), @r"
|
assert_snapshot!(test.hover(), @r"
|
||||||
<module 'mypackage.subpkg'>
|
<module 'mypackage.subpkg'>
|
||||||
---------------------------------------------
|
---------------------------------------------
|
||||||
```python
|
```xml
|
||||||
<module 'mypackage.subpkg'>
|
<module 'mypackage.subpkg'>
|
||||||
```
|
```
|
||||||
---------------------------------------------
|
---------------------------------------------
|
||||||
|
|
@ -3385,7 +3390,7 @@ def function():
|
||||||
assert_snapshot!(test.hover(), @r"
|
assert_snapshot!(test.hover(), @r"
|
||||||
<module 'mypackage.subpkg'>
|
<module 'mypackage.subpkg'>
|
||||||
---------------------------------------------
|
---------------------------------------------
|
||||||
```python
|
```xml
|
||||||
<module 'mypackage.subpkg'>
|
<module 'mypackage.subpkg'>
|
||||||
```
|
```
|
||||||
---------------------------------------------
|
---------------------------------------------
|
||||||
|
|
@ -3469,7 +3474,7 @@ def function():
|
||||||
assert_snapshot!(test.hover(), @r"
|
assert_snapshot!(test.hover(), @r"
|
||||||
<module 'mypackage.subpkg.submod'>
|
<module 'mypackage.subpkg.submod'>
|
||||||
---------------------------------------------
|
---------------------------------------------
|
||||||
```python
|
```xml
|
||||||
<module 'mypackage.subpkg.submod'>
|
<module 'mypackage.subpkg.submod'>
|
||||||
```
|
```
|
||||||
---------------------------------------------
|
---------------------------------------------
|
||||||
|
|
@ -3510,7 +3515,7 @@ def function():
|
||||||
assert_snapshot!(test.hover(), @r"
|
assert_snapshot!(test.hover(), @r"
|
||||||
<module 'mypackage.subpkg'>
|
<module 'mypackage.subpkg'>
|
||||||
---------------------------------------------
|
---------------------------------------------
|
||||||
```python
|
```xml
|
||||||
<module 'mypackage.subpkg'>
|
<module 'mypackage.subpkg'>
|
||||||
```
|
```
|
||||||
---------------------------------------------
|
---------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -6216,7 +6216,7 @@ mod tests {
|
||||||
assert_snapshot!(test.inlay_hints(), @r#"
|
assert_snapshot!(test.inlay_hints(), @r#"
|
||||||
from typing import Literal
|
from typing import Literal
|
||||||
|
|
||||||
a[: <special form 'Literal["a", "b", "c"]'>] = Literal['a', 'b', 'c']
|
a[: <special-form 'Literal["a", "b", "c"]'>] = Literal['a', 'b', 'c']
|
||||||
---------------------------------------------
|
---------------------------------------------
|
||||||
info[inlay-hint-location]: Inlay Hint Target
|
info[inlay-hint-location]: Inlay Hint Target
|
||||||
--> stdlib/typing.pyi:351:1
|
--> stdlib/typing.pyi:351:1
|
||||||
|
|
@ -6232,7 +6232,7 @@ mod tests {
|
||||||
|
|
|
|
||||||
2 | from typing import Literal
|
2 | from typing import Literal
|
||||||
3 |
|
3 |
|
||||||
4 | a[: <special form 'Literal["a", "b", "c"]'>] = Literal['a', 'b', 'c']
|
4 | a[: <special-form 'Literal["a", "b", "c"]'>] = Literal['a', 'b', 'c']
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
|
|
|
|
||||||
|
|
||||||
|
|
@ -6250,7 +6250,7 @@ mod tests {
|
||||||
|
|
|
|
||||||
2 | from typing import Literal
|
2 | from typing import Literal
|
||||||
3 |
|
3 |
|
||||||
4 | a[: <special form 'Literal["a", "b", "c"]'>] = Literal['a', 'b', 'c']
|
4 | a[: <special-form 'Literal["a", "b", "c"]'>] = Literal['a', 'b', 'c']
|
||||||
| ^^^
|
| ^^^
|
||||||
|
|
|
|
||||||
|
|
||||||
|
|
@ -6268,7 +6268,7 @@ mod tests {
|
||||||
|
|
|
|
||||||
2 | from typing import Literal
|
2 | from typing import Literal
|
||||||
3 |
|
3 |
|
||||||
4 | a[: <special form 'Literal["a", "b", "c"]'>] = Literal['a', 'b', 'c']
|
4 | a[: <special-form 'Literal["a", "b", "c"]'>] = Literal['a', 'b', 'c']
|
||||||
| ^^^
|
| ^^^
|
||||||
|
|
|
|
||||||
|
|
||||||
|
|
@ -6286,7 +6286,7 @@ mod tests {
|
||||||
|
|
|
|
||||||
2 | from typing import Literal
|
2 | from typing import Literal
|
||||||
3 |
|
3 |
|
||||||
4 | a[: <special form 'Literal["a", "b", "c"]'>] = Literal['a', 'b', 'c']
|
4 | a[: <special-form 'Literal["a", "b", "c"]'>] = Literal['a', 'b', 'c']
|
||||||
| ^^^
|
| ^^^
|
||||||
|
|
|
|
||||||
"#);
|
"#);
|
||||||
|
|
@ -6636,7 +6636,7 @@ mod tests {
|
||||||
assert_snapshot!(test.inlay_hints(), @r"
|
assert_snapshot!(test.inlay_hints(), @r"
|
||||||
from typing import Protocol, TypeVar
|
from typing import Protocol, TypeVar
|
||||||
T = TypeVar([name=]'T')
|
T = TypeVar([name=]'T')
|
||||||
Strange[: <special form 'typing.Protocol[T]'>] = Protocol[T]
|
Strange[: <special-form 'typing.Protocol[T]'>] = Protocol[T]
|
||||||
---------------------------------------------
|
---------------------------------------------
|
||||||
info[inlay-hint-location]: Inlay Hint Target
|
info[inlay-hint-location]: Inlay Hint Target
|
||||||
--> stdlib/typing.pyi:276:13
|
--> stdlib/typing.pyi:276:13
|
||||||
|
|
@ -6654,7 +6654,7 @@ mod tests {
|
||||||
2 | from typing import Protocol, TypeVar
|
2 | from typing import Protocol, TypeVar
|
||||||
3 | T = TypeVar([name=]'T')
|
3 | T = TypeVar([name=]'T')
|
||||||
| ^^^^
|
| ^^^^
|
||||||
4 | Strange[: <special form 'typing.Protocol[T]'>] = Protocol[T]
|
4 | Strange[: <special-form 'typing.Protocol[T]'>] = Protocol[T]
|
||||||
|
|
|
|
||||||
|
|
||||||
info[inlay-hint-location]: Inlay Hint Target
|
info[inlay-hint-location]: Inlay Hint Target
|
||||||
|
|
@ -6671,7 +6671,7 @@ mod tests {
|
||||||
|
|
|
|
||||||
2 | from typing import Protocol, TypeVar
|
2 | from typing import Protocol, TypeVar
|
||||||
3 | T = TypeVar([name=]'T')
|
3 | T = TypeVar([name=]'T')
|
||||||
4 | Strange[: <special form 'typing.Protocol[T]'>] = Protocol[T]
|
4 | Strange[: <special-form 'typing.Protocol[T]'>] = Protocol[T]
|
||||||
| ^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
|
|
||||||
|
|
@ -6688,7 +6688,7 @@ mod tests {
|
||||||
|
|
|
|
||||||
2 | from typing import Protocol, TypeVar
|
2 | from typing import Protocol, TypeVar
|
||||||
3 | T = TypeVar([name=]'T')
|
3 | T = TypeVar([name=]'T')
|
||||||
4 | Strange[: <special form 'typing.Protocol[T]'>] = Protocol[T]
|
4 | Strange[: <special-form 'typing.Protocol[T]'>] = Protocol[T]
|
||||||
| ^
|
| ^
|
||||||
|
|
|
|
||||||
");
|
");
|
||||||
|
|
|
||||||
|
|
@ -169,13 +169,13 @@ def f(x: Any[int]):
|
||||||
`Any` cannot be called (this leads to a `TypeError` at runtime):
|
`Any` cannot be called (this leads to a `TypeError` at runtime):
|
||||||
|
|
||||||
```py
|
```py
|
||||||
Any() # error: [call-non-callable] "Object of type `<special form 'typing.Any'>` is not callable"
|
Any() # error: [call-non-callable] "Object of type `<special-form 'typing.Any'>` is not callable"
|
||||||
```
|
```
|
||||||
|
|
||||||
`Any` also cannot be used as a metaclass (under the hood, this leads to an implicit call to `Any`):
|
`Any` also cannot be used as a metaclass (under the hood, this leads to an implicit call to `Any`):
|
||||||
|
|
||||||
```py
|
```py
|
||||||
class F(metaclass=Any): ... # error: [invalid-metaclass] "Metaclass type `<special form 'typing.Any'>` is not callable"
|
class F(metaclass=Any): ... # error: [invalid-metaclass] "Metaclass type `<special-form 'typing.Any'>` is not callable"
|
||||||
```
|
```
|
||||||
|
|
||||||
And `Any` cannot be used in `isinstance()` checks:
|
And `Any` cannot be used in `isinstance()` checks:
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ python-version = "3.11"
|
||||||
```py
|
```py
|
||||||
from typing import Never
|
from typing import Never
|
||||||
|
|
||||||
reveal_type(Never) # revealed: <special form 'typing.Never'>
|
reveal_type(Never) # revealed: <special-form 'typing.Never'>
|
||||||
```
|
```
|
||||||
|
|
||||||
### Python 3.10
|
### Python 3.10
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ python-version = "3.10"
|
||||||
class A: ...
|
class A: ...
|
||||||
class B: ...
|
class B: ...
|
||||||
|
|
||||||
reveal_type(A | B) # revealed: <types.UnionType special form 'A | B'>
|
reveal_type(A | B) # revealed: <types.UnionType special-form 'A | B'>
|
||||||
```
|
```
|
||||||
|
|
||||||
## Union of two classes (prior to 3.10)
|
## Union of two classes (prior to 3.10)
|
||||||
|
|
@ -43,14 +43,14 @@ class A: ...
|
||||||
class B: ...
|
class B: ...
|
||||||
|
|
||||||
def _(sub_a: type[A], sub_b: type[B]):
|
def _(sub_a: type[A], sub_b: type[B]):
|
||||||
reveal_type(A | sub_b) # revealed: <types.UnionType special form>
|
reveal_type(A | sub_b) # revealed: <types.UnionType special-form>
|
||||||
reveal_type(sub_a | B) # revealed: <types.UnionType special form>
|
reveal_type(sub_a | B) # revealed: <types.UnionType special-form>
|
||||||
reveal_type(sub_a | sub_b) # revealed: <types.UnionType special form>
|
reveal_type(sub_a | sub_b) # revealed: <types.UnionType special-form>
|
||||||
|
|
||||||
class C[T]: ...
|
class C[T]: ...
|
||||||
class D[T]: ...
|
class D[T]: ...
|
||||||
|
|
||||||
reveal_type(C | D) # revealed: <types.UnionType special form 'C[Unknown] | D[Unknown]'>
|
reveal_type(C | D) # revealed: <types.UnionType special-form 'C[Unknown] | D[Unknown]'>
|
||||||
|
|
||||||
reveal_type(C[int] | D[str]) # revealed: <types.UnionType special form 'C[int] | D[str]'>
|
reveal_type(C[int] | D[str]) # revealed: <types.UnionType special-form 'C[int] | D[str]'>
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -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()`.
|
# 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()`.
|
# 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] "`<special form 'typing.ChainMap'>` is not a valid class"
|
# error: [invalid-super-argument] "`<special-form 'typing.ChainMap'>` is not a valid class"
|
||||||
reveal_type(super(typing.ChainMap, collections.ChainMap())) # revealed: Unknown
|
reveal_type(super(typing.ChainMap, collections.ChainMap())) # revealed: Unknown
|
||||||
|
|
||||||
# Meanwhile, it's not valid to inherit from unsubscripted `typing.Generic`,
|
# Meanwhile, it's not valid to inherit from unsubscripted `typing.Generic`,
|
||||||
# but it *is* valid as the first argument to `super()`.
|
# but it *is* valid as the first argument to `super()`.
|
||||||
#
|
#
|
||||||
# revealed: <super: <special form 'typing.Generic'>, <class 'SupportsInt'>>
|
# revealed: <super: <special-form 'typing.Generic'>, <class 'SupportsInt'>>
|
||||||
reveal_type(super(typing.Generic, typing.SupportsInt))
|
reveal_type(super(typing.Generic, typing.SupportsInt))
|
||||||
|
|
||||||
def _(x: type[typing.Any], y: typing.Any):
|
def _(x: type[typing.Any], y: typing.Any):
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ class Foo(Protocol):
|
||||||
def f[T](self, v: T) -> T: ...
|
def f[T](self, v: T) -> T: ...
|
||||||
|
|
||||||
t = (Protocol, int)
|
t = (Protocol, int)
|
||||||
reveal_type(t[0]) # revealed: <special form 'typing.Protocol'>
|
reveal_type(t[0]) # revealed: <special-form 'typing.Protocol'>
|
||||||
|
|
||||||
class Lorem(t[0]):
|
class Lorem(t[0]):
|
||||||
def f(self) -> int: ...
|
def f(self) -> int: ...
|
||||||
|
|
|
||||||
|
|
@ -77,44 +77,44 @@ IntOrTypeVar = int | T
|
||||||
TypeVarOrNone = T | None
|
TypeVarOrNone = T | None
|
||||||
NoneOrTypeVar = None | T
|
NoneOrTypeVar = None | T
|
||||||
|
|
||||||
reveal_type(IntOrStr) # revealed: <types.UnionType special form 'int | str'>
|
reveal_type(IntOrStr) # revealed: <types.UnionType special-form 'int | str'>
|
||||||
reveal_type(IntOrStrOrBytes1) # revealed: <types.UnionType special form 'int | str | bytes'>
|
reveal_type(IntOrStrOrBytes1) # revealed: <types.UnionType special-form 'int | str | bytes'>
|
||||||
reveal_type(IntOrStrOrBytes2) # revealed: <types.UnionType special form 'int | str | bytes'>
|
reveal_type(IntOrStrOrBytes2) # revealed: <types.UnionType special-form 'int | str | bytes'>
|
||||||
reveal_type(IntOrStrOrBytes3) # revealed: <types.UnionType special form 'int | str | bytes'>
|
reveal_type(IntOrStrOrBytes3) # revealed: <types.UnionType special-form 'int | str | bytes'>
|
||||||
reveal_type(IntOrStrOrBytes4) # revealed: <types.UnionType special form 'int | str | bytes'>
|
reveal_type(IntOrStrOrBytes4) # revealed: <types.UnionType special-form 'int | str | bytes'>
|
||||||
reveal_type(IntOrStrOrBytes5) # revealed: <types.UnionType special form 'int | str | bytes'>
|
reveal_type(IntOrStrOrBytes5) # revealed: <types.UnionType special-form 'int | str | bytes'>
|
||||||
reveal_type(IntOrStrOrBytes6) # revealed: <types.UnionType special form 'int | str | bytes'>
|
reveal_type(IntOrStrOrBytes6) # revealed: <types.UnionType special-form 'int | str | bytes'>
|
||||||
reveal_type(BytesOrIntOrStr) # revealed: <types.UnionType special form 'bytes | int | str'>
|
reveal_type(BytesOrIntOrStr) # revealed: <types.UnionType special-form 'bytes | int | str'>
|
||||||
reveal_type(IntOrNone) # revealed: <types.UnionType special form 'int | None'>
|
reveal_type(IntOrNone) # revealed: <types.UnionType special-form 'int | None'>
|
||||||
reveal_type(NoneOrInt) # revealed: <types.UnionType special form 'None | int'>
|
reveal_type(NoneOrInt) # revealed: <types.UnionType special-form 'None | int'>
|
||||||
reveal_type(IntOrStrOrNone) # revealed: <types.UnionType special form 'int | str | None'>
|
reveal_type(IntOrStrOrNone) # revealed: <types.UnionType special-form 'int | str | None'>
|
||||||
reveal_type(NoneOrIntOrStr) # revealed: <types.UnionType special form 'None | int | str'>
|
reveal_type(NoneOrIntOrStr) # revealed: <types.UnionType special-form 'None | int | str'>
|
||||||
reveal_type(IntOrAny) # revealed: <types.UnionType special form 'int | Any'>
|
reveal_type(IntOrAny) # revealed: <types.UnionType special-form 'int | Any'>
|
||||||
reveal_type(AnyOrInt) # revealed: <types.UnionType special form 'Any | int'>
|
reveal_type(AnyOrInt) # revealed: <types.UnionType special-form 'Any | int'>
|
||||||
reveal_type(NoneOrAny) # revealed: <types.UnionType special form 'None | Any'>
|
reveal_type(NoneOrAny) # revealed: <types.UnionType special-form 'None | Any'>
|
||||||
reveal_type(AnyOrNone) # revealed: <types.UnionType special form 'Any | None'>
|
reveal_type(AnyOrNone) # revealed: <types.UnionType special-form 'Any | None'>
|
||||||
reveal_type(NeverOrAny) # revealed: <types.UnionType special form 'Any'>
|
reveal_type(NeverOrAny) # revealed: <types.UnionType special-form 'Any'>
|
||||||
reveal_type(AnyOrNever) # revealed: <types.UnionType special form 'Any'>
|
reveal_type(AnyOrNever) # revealed: <types.UnionType special-form 'Any'>
|
||||||
reveal_type(UnknownOrInt) # revealed: <types.UnionType special form 'Unknown | int'>
|
reveal_type(UnknownOrInt) # revealed: <types.UnionType special-form 'Unknown | int'>
|
||||||
reveal_type(IntOrUnknown) # revealed: <types.UnionType special form 'int | Unknown'>
|
reveal_type(IntOrUnknown) # revealed: <types.UnionType special-form 'int | Unknown'>
|
||||||
reveal_type(StrOrZero) # revealed: <types.UnionType special form 'str | Literal[0]'>
|
reveal_type(StrOrZero) # revealed: <types.UnionType special-form 'str | Literal[0]'>
|
||||||
reveal_type(ZeroOrStr) # revealed: <types.UnionType special form 'Literal[0] | str'>
|
reveal_type(ZeroOrStr) # revealed: <types.UnionType special-form 'Literal[0] | str'>
|
||||||
reveal_type(IntOrLiteralString) # revealed: <types.UnionType special form 'int | LiteralString'>
|
reveal_type(IntOrLiteralString) # revealed: <types.UnionType special-form 'int | LiteralString'>
|
||||||
reveal_type(LiteralStringOrInt) # revealed: <types.UnionType special form 'LiteralString | int'>
|
reveal_type(LiteralStringOrInt) # revealed: <types.UnionType special-form 'LiteralString | int'>
|
||||||
reveal_type(NoneOrTuple) # revealed: <types.UnionType special form 'None | tuple[int, str]'>
|
reveal_type(NoneOrTuple) # revealed: <types.UnionType special-form 'None | tuple[int, str]'>
|
||||||
reveal_type(TupleOrNone) # revealed: <types.UnionType special form 'tuple[int, str] | None'>
|
reveal_type(TupleOrNone) # revealed: <types.UnionType special-form 'tuple[int, str] | None'>
|
||||||
reveal_type(IntOrAnnotated) # revealed: <types.UnionType special form 'int | str'>
|
reveal_type(IntOrAnnotated) # revealed: <types.UnionType special-form 'int | str'>
|
||||||
reveal_type(AnnotatedOrInt) # revealed: <types.UnionType special form 'str | int'>
|
reveal_type(AnnotatedOrInt) # revealed: <types.UnionType special-form 'str | int'>
|
||||||
reveal_type(IntOrOptional) # revealed: <types.UnionType special form 'int | str | None'>
|
reveal_type(IntOrOptional) # revealed: <types.UnionType special-form 'int | str | None'>
|
||||||
reveal_type(OptionalOrInt) # revealed: <types.UnionType special form 'str | None | int'>
|
reveal_type(OptionalOrInt) # revealed: <types.UnionType special-form 'str | None | int'>
|
||||||
reveal_type(IntOrTypeOfStr) # revealed: <types.UnionType special form 'int | type[str]'>
|
reveal_type(IntOrTypeOfStr) # revealed: <types.UnionType special-form 'int | type[str]'>
|
||||||
reveal_type(TypeOfStrOrInt) # revealed: <types.UnionType special form 'type[str] | int'>
|
reveal_type(TypeOfStrOrInt) # revealed: <types.UnionType special-form 'type[str] | int'>
|
||||||
reveal_type(IntOrCallable) # revealed: <types.UnionType special form 'int | ((str, /) -> bytes)'>
|
reveal_type(IntOrCallable) # revealed: <types.UnionType special-form 'int | ((str, /) -> bytes)'>
|
||||||
reveal_type(CallableOrInt) # revealed: <types.UnionType special form '((str, /) -> bytes) | int'>
|
reveal_type(CallableOrInt) # revealed: <types.UnionType special-form '((str, /) -> bytes) | int'>
|
||||||
reveal_type(TypeVarOrInt) # revealed: <types.UnionType special form 'T@TypeVarOrInt | int'>
|
reveal_type(TypeVarOrInt) # revealed: <types.UnionType special-form 'T@TypeVarOrInt | int'>
|
||||||
reveal_type(IntOrTypeVar) # revealed: <types.UnionType special form 'int | T@IntOrTypeVar'>
|
reveal_type(IntOrTypeVar) # revealed: <types.UnionType special-form 'int | T@IntOrTypeVar'>
|
||||||
reveal_type(TypeVarOrNone) # revealed: <types.UnionType special form 'T@TypeVarOrNone | None'>
|
reveal_type(TypeVarOrNone) # revealed: <types.UnionType special-form 'T@TypeVarOrNone | None'>
|
||||||
reveal_type(NoneOrTypeVar) # revealed: <types.UnionType special form 'None | T@NoneOrTypeVar'>
|
reveal_type(NoneOrTypeVar) # revealed: <types.UnionType special-form 'None | T@NoneOrTypeVar'>
|
||||||
|
|
||||||
def _(
|
def _(
|
||||||
int_or_str: IntOrStr,
|
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`?
|
# 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)
|
# But we still need to record what the elements are, since (according to the typing spec)
|
||||||
# `X` is still a valid type alias
|
# `X` is still a valid type alias
|
||||||
reveal_type(X) # revealed: <types.UnionType special form 'Foo | Bar'>
|
reveal_type(X) # revealed: <types.UnionType special-form 'Foo | Bar'>
|
||||||
|
|
||||||
def f(obj: X):
|
def f(obj: X):
|
||||||
reveal_type(obj) # revealed: Foo | Bar
|
reveal_type(obj) # revealed: Foo | Bar
|
||||||
|
|
@ -391,17 +391,17 @@ MyOptional = T | None
|
||||||
|
|
||||||
reveal_type(MyList) # revealed: <class 'list[T@MyList]'>
|
reveal_type(MyList) # revealed: <class 'list[T@MyList]'>
|
||||||
reveal_type(MyDict) # revealed: <class 'dict[T@MyDict, U@MyDict]'>
|
reveal_type(MyDict) # revealed: <class 'dict[T@MyDict, U@MyDict]'>
|
||||||
reveal_type(MyType) # revealed: <special form 'type[T@MyType]'>
|
reveal_type(MyType) # revealed: <special-form 'type[T@MyType]'>
|
||||||
reveal_type(IntAndType) # revealed: <class 'tuple[int, T@IntAndType]'>
|
reveal_type(IntAndType) # revealed: <class 'tuple[int, T@IntAndType]'>
|
||||||
reveal_type(Pair) # revealed: <class 'tuple[T@Pair, T@Pair]'>
|
reveal_type(Pair) # revealed: <class 'tuple[T@Pair, T@Pair]'>
|
||||||
reveal_type(Sum) # revealed: <class 'tuple[T@Sum, U@Sum]'>
|
reveal_type(Sum) # revealed: <class 'tuple[T@Sum, U@Sum]'>
|
||||||
reveal_type(ListOrTuple) # revealed: <types.UnionType special form 'list[T@ListOrTuple] | tuple[T@ListOrTuple, ...]'>
|
reveal_type(ListOrTuple) # revealed: <types.UnionType special-form 'list[T@ListOrTuple] | tuple[T@ListOrTuple, ...]'>
|
||||||
# revealed: <types.UnionType special form 'list[T@ListOrTupleLegacy] | tuple[T@ListOrTupleLegacy, ...]'>
|
# revealed: <types.UnionType special-form 'list[T@ListOrTupleLegacy] | tuple[T@ListOrTupleLegacy, ...]'>
|
||||||
reveal_type(ListOrTupleLegacy)
|
reveal_type(ListOrTupleLegacy)
|
||||||
reveal_type(MyCallable) # revealed: <typing.Callable special form '(**P@MyCallable) -> T@MyCallable'>
|
reveal_type(MyCallable) # revealed: <typing.Callable special-form '(**P@MyCallable) -> T@MyCallable'>
|
||||||
reveal_type(AnnotatedType) # revealed: <special form 'typing.Annotated[T@AnnotatedType, <metadata>]'>
|
reveal_type(AnnotatedType) # revealed: <special-form 'typing.Annotated[T@AnnotatedType, <metadata>]'>
|
||||||
reveal_type(TransparentAlias) # revealed: TypeVar
|
reveal_type(TransparentAlias) # revealed: TypeVar
|
||||||
reveal_type(MyOptional) # revealed: <types.UnionType special form 'T@MyOptional | None'>
|
reveal_type(MyOptional) # revealed: <types.UnionType special-form 'T@MyOptional | None'>
|
||||||
|
|
||||||
def _(
|
def _(
|
||||||
list_of_ints: MyList[int],
|
list_of_ints: MyList[int],
|
||||||
|
|
@ -457,13 +457,13 @@ AnnotatedInt = AnnotatedType[int]
|
||||||
SubclassOfInt = MyType[int]
|
SubclassOfInt = MyType[int]
|
||||||
CallableIntToStr = MyCallable[[int], str]
|
CallableIntToStr = MyCallable[[int], str]
|
||||||
|
|
||||||
reveal_type(IntsOrNone) # revealed: <types.UnionType special form 'list[int] | None'>
|
reveal_type(IntsOrNone) # revealed: <types.UnionType special-form 'list[int] | None'>
|
||||||
reveal_type(IntsOrStrs) # revealed: <types.UnionType special form 'tuple[int, int] | tuple[str, str]'>
|
reveal_type(IntsOrStrs) # revealed: <types.UnionType special-form 'tuple[int, int] | tuple[str, str]'>
|
||||||
reveal_type(ListOfPairs) # revealed: <class 'list[tuple[str, str]]'>
|
reveal_type(ListOfPairs) # revealed: <class 'list[tuple[str, str]]'>
|
||||||
reveal_type(ListOrTupleOfInts) # revealed: <types.UnionType special form 'list[int] | tuple[int, ...]'>
|
reveal_type(ListOrTupleOfInts) # revealed: <types.UnionType special-form 'list[int] | tuple[int, ...]'>
|
||||||
reveal_type(AnnotatedInt) # revealed: <special form 'typing.Annotated[int, <metadata>]'>
|
reveal_type(AnnotatedInt) # revealed: <special-form 'typing.Annotated[int, <metadata>]'>
|
||||||
reveal_type(SubclassOfInt) # revealed: <special form 'type[int]'>
|
reveal_type(SubclassOfInt) # revealed: <special-form 'type[int]'>
|
||||||
reveal_type(CallableIntToStr) # revealed: <typing.Callable special form '(int, /) -> str'>
|
reveal_type(CallableIntToStr) # revealed: <typing.Callable special-form '(int, /) -> str'>
|
||||||
|
|
||||||
def _(
|
def _(
|
||||||
ints_or_none: IntsOrNone,
|
ints_or_none: IntsOrNone,
|
||||||
|
|
@ -495,8 +495,8 @@ MyOtherType = MyType[T]
|
||||||
TypeOrList = MyType[B] | MyList[B]
|
TypeOrList = MyType[B] | MyList[B]
|
||||||
|
|
||||||
reveal_type(MyOtherList) # revealed: <class 'list[T@MyOtherList]'>
|
reveal_type(MyOtherList) # revealed: <class 'list[T@MyOtherList]'>
|
||||||
reveal_type(MyOtherType) # revealed: <special form 'type[T@MyOtherType]'>
|
reveal_type(MyOtherType) # revealed: <special-form 'type[T@MyOtherType]'>
|
||||||
reveal_type(TypeOrList) # revealed: <types.UnionType special form 'type[B@TypeOrList] | list[B@TypeOrList]'>
|
reveal_type(TypeOrList) # revealed: <types.UnionType special-form 'type[B@TypeOrList] | list[B@TypeOrList]'>
|
||||||
|
|
||||||
def _(
|
def _(
|
||||||
list_of_ints: MyOtherList[int],
|
list_of_ints: MyOtherList[int],
|
||||||
|
|
@ -730,7 +730,7 @@ def _(doubly_specialized: DictInt[int]):
|
||||||
|
|
||||||
Union = list[str] | list[int]
|
Union = list[str] | list[int]
|
||||||
|
|
||||||
# error: [non-subscriptable] "Cannot subscript non-generic type: `<types.UnionType special form 'list[str] | list[int]'>` is already specialized"
|
# error: [non-subscriptable] "Cannot subscript non-generic type: `<types.UnionType special-form 'list[str] | list[int]'>` is already specialized"
|
||||||
def _(doubly_specialized: Union[int]):
|
def _(doubly_specialized: Union[int]):
|
||||||
reveal_type(doubly_specialized) # revealed: Unknown
|
reveal_type(doubly_specialized) # revealed: Unknown
|
||||||
|
|
||||||
|
|
@ -974,7 +974,7 @@ from typing import Optional
|
||||||
|
|
||||||
MyOptionalInt = Optional[int]
|
MyOptionalInt = Optional[int]
|
||||||
|
|
||||||
reveal_type(MyOptionalInt) # revealed: <types.UnionType special form 'int | None'>
|
reveal_type(MyOptionalInt) # revealed: <types.UnionType special-form 'int | None'>
|
||||||
|
|
||||||
def _(optional_int: MyOptionalInt):
|
def _(optional_int: MyOptionalInt):
|
||||||
reveal_type(optional_int) # revealed: int | None
|
reveal_type(optional_int) # revealed: int | None
|
||||||
|
|
@ -1007,9 +1007,9 @@ MyLiteralString = LiteralString
|
||||||
MyNoReturn = NoReturn
|
MyNoReturn = NoReturn
|
||||||
MyNever = Never
|
MyNever = Never
|
||||||
|
|
||||||
reveal_type(MyLiteralString) # revealed: <special form 'typing.LiteralString'>
|
reveal_type(MyLiteralString) # revealed: <special-form 'typing.LiteralString'>
|
||||||
reveal_type(MyNoReturn) # revealed: <special form 'typing.NoReturn'>
|
reveal_type(MyNoReturn) # revealed: <special-form 'typing.NoReturn'>
|
||||||
reveal_type(MyNever) # revealed: <special form 'typing.Never'>
|
reveal_type(MyNever) # revealed: <special-form 'typing.Never'>
|
||||||
|
|
||||||
def _(
|
def _(
|
||||||
ls: MyLiteralString,
|
ls: MyLiteralString,
|
||||||
|
|
@ -1062,8 +1062,8 @@ from typing import Union
|
||||||
IntOrStr = Union[int, str]
|
IntOrStr = Union[int, str]
|
||||||
IntOrStrOrBytes = Union[int, Union[str, bytes]]
|
IntOrStrOrBytes = Union[int, Union[str, bytes]]
|
||||||
|
|
||||||
reveal_type(IntOrStr) # revealed: <types.UnionType special form 'int | str'>
|
reveal_type(IntOrStr) # revealed: <types.UnionType special-form 'int | str'>
|
||||||
reveal_type(IntOrStrOrBytes) # revealed: <types.UnionType special form 'int | str | bytes'>
|
reveal_type(IntOrStrOrBytes) # revealed: <types.UnionType special-form 'int | str | bytes'>
|
||||||
|
|
||||||
def _(
|
def _(
|
||||||
int_or_str: IntOrStr,
|
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"
|
# error: [invalid-type-form] "`typing.Union` requires at least one type argument"
|
||||||
EmptyUnion = Union[()]
|
EmptyUnion = Union[()]
|
||||||
|
|
||||||
reveal_type(EmptyUnion) # revealed: <types.UnionType special form 'Never'>
|
reveal_type(EmptyUnion) # revealed: <types.UnionType special-form 'Never'>
|
||||||
|
|
||||||
def _(empty: EmptyUnion):
|
def _(empty: EmptyUnion):
|
||||||
reveal_type(empty) # revealed: Never
|
reveal_type(empty) # revealed: Never
|
||||||
|
|
@ -1136,14 +1136,14 @@ SubclassOfG = type[G]
|
||||||
SubclassOfGInt = type[G[int]]
|
SubclassOfGInt = type[G[int]]
|
||||||
SubclassOfP = type[P]
|
SubclassOfP = type[P]
|
||||||
|
|
||||||
reveal_type(SubclassOfA) # revealed: <special form 'type[A]'>
|
reveal_type(SubclassOfA) # revealed: <special-form 'type[A]'>
|
||||||
reveal_type(SubclassOfAny) # revealed: <special form 'type[Any]'>
|
reveal_type(SubclassOfAny) # revealed: <special-form 'type[Any]'>
|
||||||
reveal_type(SubclassOfAOrB1) # revealed: <special form 'type[A | B]'>
|
reveal_type(SubclassOfAOrB1) # revealed: <special-form 'type[A | B]'>
|
||||||
reveal_type(SubclassOfAOrB2) # revealed: <types.UnionType special form 'type[A] | type[B]'>
|
reveal_type(SubclassOfAOrB2) # revealed: <types.UnionType special-form 'type[A] | type[B]'>
|
||||||
reveal_type(SubclassOfAOrB3) # revealed: <types.UnionType special form 'type[A] | type[B]'>
|
reveal_type(SubclassOfAOrB3) # revealed: <types.UnionType special-form 'type[A] | type[B]'>
|
||||||
reveal_type(SubclassOfG) # revealed: <special form 'type[G[Unknown]]'>
|
reveal_type(SubclassOfG) # revealed: <special-form 'type[G[Unknown]]'>
|
||||||
reveal_type(SubclassOfGInt) # revealed: <special form 'type[G[int]]'>
|
reveal_type(SubclassOfGInt) # revealed: <special-form 'type[G[int]]'>
|
||||||
reveal_type(SubclassOfP) # revealed: <special form 'type[P]'>
|
reveal_type(SubclassOfP) # revealed: <special-form 'type[P]'>
|
||||||
|
|
||||||
def _(
|
def _(
|
||||||
subclass_of_a: SubclassOfA,
|
subclass_of_a: SubclassOfA,
|
||||||
|
|
@ -1224,14 +1224,14 @@ SubclassOfG = Type[G]
|
||||||
SubclassOfGInt = Type[G[int]]
|
SubclassOfGInt = Type[G[int]]
|
||||||
SubclassOfP = Type[P]
|
SubclassOfP = Type[P]
|
||||||
|
|
||||||
reveal_type(SubclassOfA) # revealed: <special form 'type[A]'>
|
reveal_type(SubclassOfA) # revealed: <special-form 'type[A]'>
|
||||||
reveal_type(SubclassOfAny) # revealed: <special form 'type[Any]'>
|
reveal_type(SubclassOfAny) # revealed: <special-form 'type[Any]'>
|
||||||
reveal_type(SubclassOfAOrB1) # revealed: <special form 'type[A | B]'>
|
reveal_type(SubclassOfAOrB1) # revealed: <special-form 'type[A | B]'>
|
||||||
reveal_type(SubclassOfAOrB2) # revealed: <types.UnionType special form 'type[A] | type[B]'>
|
reveal_type(SubclassOfAOrB2) # revealed: <types.UnionType special-form 'type[A] | type[B]'>
|
||||||
reveal_type(SubclassOfAOrB3) # revealed: <types.UnionType special form 'type[A] | type[B]'>
|
reveal_type(SubclassOfAOrB3) # revealed: <types.UnionType special-form 'type[A] | type[B]'>
|
||||||
reveal_type(SubclassOfG) # revealed: <special form 'type[G[Unknown]]'>
|
reveal_type(SubclassOfG) # revealed: <special-form 'type[G[Unknown]]'>
|
||||||
reveal_type(SubclassOfGInt) # revealed: <special form 'type[G[int]]'>
|
reveal_type(SubclassOfGInt) # revealed: <special-form 'type[G[int]]'>
|
||||||
reveal_type(SubclassOfP) # revealed: <special form 'type[P]'>
|
reveal_type(SubclassOfP) # revealed: <special-form 'type[P]'>
|
||||||
|
|
||||||
def _(
|
def _(
|
||||||
subclass_of_a: SubclassOfA,
|
subclass_of_a: SubclassOfA,
|
||||||
|
|
@ -1346,25 +1346,25 @@ DefaultDictOrNone = DefaultDict[str, int] | None
|
||||||
DequeOrNone = Deque[str] | None
|
DequeOrNone = Deque[str] | None
|
||||||
OrderedDictOrNone = OrderedDict[str, int] | None
|
OrderedDictOrNone = OrderedDict[str, int] | None
|
||||||
|
|
||||||
reveal_type(NoneOrList) # revealed: <types.UnionType special form 'None | list[str]'>
|
reveal_type(NoneOrList) # revealed: <types.UnionType special-form 'None | list[str]'>
|
||||||
reveal_type(NoneOrSet) # revealed: <types.UnionType special form 'None | set[str]'>
|
reveal_type(NoneOrSet) # revealed: <types.UnionType special-form 'None | set[str]'>
|
||||||
reveal_type(NoneOrDict) # revealed: <types.UnionType special form 'None | dict[str, int]'>
|
reveal_type(NoneOrDict) # revealed: <types.UnionType special-form 'None | dict[str, int]'>
|
||||||
reveal_type(NoneOrFrozenSet) # revealed: <types.UnionType special form 'None | frozenset[str]'>
|
reveal_type(NoneOrFrozenSet) # revealed: <types.UnionType special-form 'None | frozenset[str]'>
|
||||||
reveal_type(NoneOrChainMap) # revealed: <types.UnionType special form 'None | ChainMap[str, int]'>
|
reveal_type(NoneOrChainMap) # revealed: <types.UnionType special-form 'None | ChainMap[str, int]'>
|
||||||
reveal_type(NoneOrCounter) # revealed: <types.UnionType special form 'None | Counter[str]'>
|
reveal_type(NoneOrCounter) # revealed: <types.UnionType special-form 'None | Counter[str]'>
|
||||||
reveal_type(NoneOrDefaultDict) # revealed: <types.UnionType special form 'None | defaultdict[str, int]'>
|
reveal_type(NoneOrDefaultDict) # revealed: <types.UnionType special-form 'None | defaultdict[str, int]'>
|
||||||
reveal_type(NoneOrDeque) # revealed: <types.UnionType special form 'None | deque[str]'>
|
reveal_type(NoneOrDeque) # revealed: <types.UnionType special-form 'None | deque[str]'>
|
||||||
reveal_type(NoneOrOrderedDict) # revealed: <types.UnionType special form 'None | OrderedDict[str, int]'>
|
reveal_type(NoneOrOrderedDict) # revealed: <types.UnionType special-form 'None | OrderedDict[str, int]'>
|
||||||
|
|
||||||
reveal_type(ListOrNone) # revealed: <types.UnionType special form 'list[int] | None'>
|
reveal_type(ListOrNone) # revealed: <types.UnionType special-form 'list[int] | None'>
|
||||||
reveal_type(SetOrNone) # revealed: <types.UnionType special form 'set[int] | None'>
|
reveal_type(SetOrNone) # revealed: <types.UnionType special-form 'set[int] | None'>
|
||||||
reveal_type(DictOrNone) # revealed: <types.UnionType special form 'dict[str, int] | None'>
|
reveal_type(DictOrNone) # revealed: <types.UnionType special-form 'dict[str, int] | None'>
|
||||||
reveal_type(FrozenSetOrNone) # revealed: <types.UnionType special form 'frozenset[int] | None'>
|
reveal_type(FrozenSetOrNone) # revealed: <types.UnionType special-form 'frozenset[int] | None'>
|
||||||
reveal_type(ChainMapOrNone) # revealed: <types.UnionType special form 'ChainMap[str, int] | None'>
|
reveal_type(ChainMapOrNone) # revealed: <types.UnionType special-form 'ChainMap[str, int] | None'>
|
||||||
reveal_type(CounterOrNone) # revealed: <types.UnionType special form 'Counter[str] | None'>
|
reveal_type(CounterOrNone) # revealed: <types.UnionType special-form 'Counter[str] | None'>
|
||||||
reveal_type(DefaultDictOrNone) # revealed: <types.UnionType special form 'defaultdict[str, int] | None'>
|
reveal_type(DefaultDictOrNone) # revealed: <types.UnionType special-form 'defaultdict[str, int] | None'>
|
||||||
reveal_type(DequeOrNone) # revealed: <types.UnionType special form 'deque[str] | None'>
|
reveal_type(DequeOrNone) # revealed: <types.UnionType special-form 'deque[str] | None'>
|
||||||
reveal_type(OrderedDictOrNone) # revealed: <types.UnionType special form 'OrderedDict[str, int] | None'>
|
reveal_type(OrderedDictOrNone) # revealed: <types.UnionType special-form 'OrderedDict[str, int] | None'>
|
||||||
|
|
||||||
def _(
|
def _(
|
||||||
none_or_list: NoneOrList,
|
none_or_list: NoneOrList,
|
||||||
|
|
@ -1457,9 +1457,9 @@ CallableNoArgs = Callable[[], None]
|
||||||
BasicCallable = Callable[[int, str], bytes]
|
BasicCallable = Callable[[int, str], bytes]
|
||||||
GradualCallable = Callable[..., str]
|
GradualCallable = Callable[..., str]
|
||||||
|
|
||||||
reveal_type(CallableNoArgs) # revealed: <typing.Callable special form '() -> None'>
|
reveal_type(CallableNoArgs) # revealed: <typing.Callable special-form '() -> None'>
|
||||||
reveal_type(BasicCallable) # revealed: <typing.Callable special form '(int, str, /) -> bytes'>
|
reveal_type(BasicCallable) # revealed: <typing.Callable special-form '(int, str, /) -> bytes'>
|
||||||
reveal_type(GradualCallable) # revealed: <typing.Callable special form '(...) -> str'>
|
reveal_type(GradualCallable) # revealed: <typing.Callable special-form '(...) -> str'>
|
||||||
|
|
||||||
def _(
|
def _(
|
||||||
callable_no_args: CallableNoArgs,
|
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 `...`"
|
# error: [invalid-type-form] "The first argument to `Callable` must be either a list of types, ParamSpec, Concatenate, or `...`"
|
||||||
InvalidCallable2 = Callable[int, str]
|
InvalidCallable2 = Callable[int, str]
|
||||||
|
|
||||||
reveal_type(InvalidCallable1) # revealed: <typing.Callable special form '(...) -> Unknown'>
|
reveal_type(InvalidCallable1) # revealed: <typing.Callable special-form '(...) -> Unknown'>
|
||||||
reveal_type(InvalidCallable2) # revealed: <typing.Callable special form '(...) -> Unknown'>
|
reveal_type(InvalidCallable2) # revealed: <typing.Callable special-form '(...) -> Unknown'>
|
||||||
|
|
||||||
def _(invalid_callable1: InvalidCallable1, invalid_callable2: InvalidCallable2):
|
def _(invalid_callable1: InvalidCallable1, invalid_callable2: InvalidCallable2):
|
||||||
reveal_type(invalid_callable1) # revealed: (...) -> Unknown
|
reveal_type(invalid_callable1) # revealed: (...) -> Unknown
|
||||||
|
|
|
||||||
|
|
@ -53,8 +53,8 @@ in `import os.path as os.path` the `os.path` is not a valid identifier.
|
||||||
```py
|
```py
|
||||||
from b import Any, Literal, foo
|
from b import Any, Literal, foo
|
||||||
|
|
||||||
reveal_type(Any) # revealed: <special form 'typing.Any'>
|
reveal_type(Any) # revealed: <special-form 'typing.Any'>
|
||||||
reveal_type(Literal) # revealed: <special form 'typing.Literal'>
|
reveal_type(Literal) # revealed: <special-form 'typing.Literal'>
|
||||||
reveal_type(foo) # revealed: <module 'foo'>
|
reveal_type(foo) # revealed: <module 'foo'>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -132,7 +132,7 @@ reveal_type(Any) # revealed: Unknown
|
||||||
```pyi
|
```pyi
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
reveal_type(Any) # revealed: <special form 'typing.Any'>
|
reveal_type(Any) # revealed: <special-form 'typing.Any'>
|
||||||
```
|
```
|
||||||
|
|
||||||
## Nested mixed re-export and not
|
## Nested mixed re-export and not
|
||||||
|
|
@ -169,7 +169,7 @@ reveal_type(Any) # revealed: Unknown
|
||||||
```pyi
|
```pyi
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
reveal_type(Any) # revealed: <special form 'typing.Any'>
|
reveal_type(Any) # revealed: <special-form 'typing.Any'>
|
||||||
```
|
```
|
||||||
|
|
||||||
## Exported as different name
|
## Exported as different name
|
||||||
|
|
|
||||||
|
|
@ -1437,7 +1437,7 @@ are present due to `*` imports.
|
||||||
import collections.abc
|
import collections.abc
|
||||||
|
|
||||||
reveal_type(collections.abc.Sequence) # revealed: <class 'Sequence'>
|
reveal_type(collections.abc.Sequence) # revealed: <class 'Sequence'>
|
||||||
reveal_type(collections.abc.Callable) # revealed: <special form 'typing.Callable'>
|
reveal_type(collections.abc.Callable) # revealed: <special-form 'typing.Callable'>
|
||||||
reveal_type(collections.abc.Set) # revealed: <class 'AbstractSet'>
|
reveal_type(collections.abc.Set) # revealed: <class 'AbstractSet'>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -301,7 +301,7 @@ class B: ...
|
||||||
|
|
||||||
EitherOr = A | B
|
EitherOr = A | B
|
||||||
|
|
||||||
# error: [invalid-base] "Invalid class base with type `<types.UnionType special form 'A | B'>`"
|
# error: [invalid-base] "Invalid class base with type `<types.UnionType special-form 'A | B'>`"
|
||||||
class Foo(EitherOr): ...
|
class Foo(EitherOr): ...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -156,7 +156,7 @@ from typing import Union
|
||||||
|
|
||||||
IntOrStr = Union[int, str]
|
IntOrStr = Union[int, str]
|
||||||
|
|
||||||
reveal_type(IntOrStr) # revealed: <types.UnionType special form 'int | str'>
|
reveal_type(IntOrStr) # revealed: <types.UnionType special-form 'int | str'>
|
||||||
|
|
||||||
def _(x: int | str | bytes | memoryview | range):
|
def _(x: int | str | bytes | memoryview | range):
|
||||||
if isinstance(x, IntOrStr):
|
if isinstance(x, IntOrStr):
|
||||||
|
|
|
||||||
|
|
@ -209,7 +209,7 @@ from typing import Union
|
||||||
|
|
||||||
IntOrStr = Union[int, str]
|
IntOrStr = Union[int, str]
|
||||||
|
|
||||||
reveal_type(IntOrStr) # revealed: <types.UnionType special form 'int | str'>
|
reveal_type(IntOrStr) # revealed: <types.UnionType special-form 'int | str'>
|
||||||
|
|
||||||
def f(x: type[int | str | bytes | range]):
|
def f(x: type[int | str | bytes | range]):
|
||||||
if issubclass(x, IntOrStr):
|
if issubclass(x, IntOrStr):
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ MyList: TypeAlias = list[T]
|
||||||
ListOrSet: TypeAlias = list[T] | set[T]
|
ListOrSet: TypeAlias = list[T] | set[T]
|
||||||
|
|
||||||
reveal_type(MyList) # revealed: <class 'list[T]'>
|
reveal_type(MyList) # revealed: <class 'list[T]'>
|
||||||
reveal_type(ListOrSet) # revealed: <types.UnionType special form 'list[T] | set[T]'>
|
reveal_type(ListOrSet) # revealed: <types.UnionType special-form 'list[T] | set[T]'>
|
||||||
|
|
||||||
def _(list_of_int: MyList[int], list_or_set_of_str: ListOrSet[str]):
|
def _(list_of_int: MyList[int], list_or_set_of_str: ListOrSet[str]):
|
||||||
reveal_type(list_of_int) # revealed: list[int]
|
reveal_type(list_of_int) # revealed: list[int]
|
||||||
|
|
@ -293,7 +293,7 @@ def _(rec: RecursiveHomogeneousTuple):
|
||||||
reveal_type(rec) # revealed: tuple[Divergent, ...]
|
reveal_type(rec) # revealed: tuple[Divergent, ...]
|
||||||
|
|
||||||
ClassInfo: TypeAlias = type | UnionType | tuple["ClassInfo", ...]
|
ClassInfo: TypeAlias = type | UnionType | tuple["ClassInfo", ...]
|
||||||
reveal_type(ClassInfo) # revealed: <types.UnionType special form 'type | UnionType | tuple[Divergent, ...]'>
|
reveal_type(ClassInfo) # revealed: <types.UnionType special-form 'type | UnionType | tuple[Divergent, ...]'>
|
||||||
|
|
||||||
def my_isinstance(obj: object, classinfo: ClassInfo) -> bool:
|
def my_isinstance(obj: object, classinfo: ClassInfo) -> bool:
|
||||||
# TODO should be `type | UnionType | tuple[ClassInfo, ...]`
|
# TODO should be `type | UnionType | tuple[ClassInfo, ...]`
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ error[invalid-argument-type]: Invalid second argument to `isinstance`
|
||||||
10 | # error: [invalid-argument-type]
|
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: A `UnionType` instance can only be used as the second argument to `isinstance` if all elements are class objects
|
||||||
info: Elements `<special form 'Literal[42]'>` and `<class 'list[int]'>` in the union are not class objects
|
info: Elements `<special-form 'Literal[42]'>` and `<class 'list[int]'>` in the union are not class objects
|
||||||
info: rule `invalid-argument-type` is enabled by default
|
info: rule `invalid-argument-type` is enabled by default
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
@ -82,7 +82,7 @@ error[invalid-argument-type]: Invalid second argument to `isinstance`
|
||||||
13 | else:
|
13 | else:
|
||||||
|
|
|
|
||||||
info: A `UnionType` instance can only be used as the second argument to `isinstance` if all elements are class objects
|
info: A `UnionType` instance can only be used as the second argument to `isinstance` if all elements are class objects
|
||||||
info: Element `<special form 'typing.Any'>` in the union, and 2 more elements, are not class objects
|
info: Element `<special-form 'typing.Any'>` in the union, and 2 more elements, are not class objects
|
||||||
info: rule `invalid-argument-type` is enabled by default
|
info: rule `invalid-argument-type` is enabled by default
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/mro.md
|
||||||
# Diagnostics
|
# Diagnostics
|
||||||
|
|
||||||
```
|
```
|
||||||
error[inconsistent-mro]: Cannot create a consistent method resolution order (MRO) for class `Baz` with bases list `[<special form 'typing.Protocol[T]'>, <class 'Foo'>, <class 'Bar[T@Baz]'>]`
|
error[inconsistent-mro]: Cannot create a consistent method resolution order (MRO) for class `Baz` with bases list `[<special-form 'typing.Protocol[T]'>, <class 'Foo'>, <class 'Bar[T@Baz]'>]`
|
||||||
--> src/mdtest_snippet.py:7:1
|
--> src/mdtest_snippet.py:7:1
|
||||||
|
|
|
|
||||||
5 | class Foo(Protocol): ...
|
5 | class Foo(Protocol): ...
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/protocols.md
|
||||||
# Diagnostics
|
# Diagnostics
|
||||||
|
|
||||||
```
|
```
|
||||||
error[call-non-callable]: Object of type `<special form 'typing.Protocol'>` is not callable
|
error[call-non-callable]: Object of type `<special-form 'typing.Protocol'>` is not callable
|
||||||
--> src/mdtest_snippet.py:4:13
|
--> src/mdtest_snippet.py:4:13
|
||||||
|
|
|
|
||||||
3 | # error: [call-non-callable]
|
3 | # error: [call-non-callable]
|
||||||
|
|
|
||||||
|
|
@ -709,7 +709,7 @@ impl<'db> FmtDetailed<'db> for DisplayRepresentation<'db> {
|
||||||
},
|
},
|
||||||
Type::SpecialForm(special_form) => {
|
Type::SpecialForm(special_form) => {
|
||||||
f.set_invalid_syntax();
|
f.set_invalid_syntax();
|
||||||
write!(f.with_type(self.ty), "<special form '{special_form}'>")
|
write!(f.with_type(self.ty), "<special-form '{special_form}'>")
|
||||||
}
|
}
|
||||||
Type::KnownInstance(known_instance) => known_instance
|
Type::KnownInstance(known_instance) => known_instance
|
||||||
.display_with(self.db, self.settings.clone())
|
.display_with(self.db, self.settings.clone())
|
||||||
|
|
@ -2334,7 +2334,7 @@ impl<'db> FmtDetailed<'db> for DisplayKnownInstanceRepr<'db> {
|
||||||
match self.known_instance {
|
match self.known_instance {
|
||||||
KnownInstanceType::SubscriptedProtocol(generic_context) => {
|
KnownInstanceType::SubscriptedProtocol(generic_context) => {
|
||||||
f.set_invalid_syntax();
|
f.set_invalid_syntax();
|
||||||
f.write_str("<special form '")?;
|
f.write_str("<special-form '")?;
|
||||||
f.with_type(Type::SpecialForm(SpecialFormType::Protocol))
|
f.with_type(Type::SpecialForm(SpecialFormType::Protocol))
|
||||||
.write_str("typing.Protocol")?;
|
.write_str("typing.Protocol")?;
|
||||||
generic_context.display(self.db).fmt_detailed(f)?;
|
generic_context.display(self.db).fmt_detailed(f)?;
|
||||||
|
|
@ -2342,7 +2342,7 @@ impl<'db> FmtDetailed<'db> for DisplayKnownInstanceRepr<'db> {
|
||||||
}
|
}
|
||||||
KnownInstanceType::SubscriptedGeneric(generic_context) => {
|
KnownInstanceType::SubscriptedGeneric(generic_context) => {
|
||||||
f.set_invalid_syntax();
|
f.set_invalid_syntax();
|
||||||
f.write_str("<special form '")?;
|
f.write_str("<special-form '")?;
|
||||||
f.with_type(Type::SpecialForm(SpecialFormType::Generic))
|
f.with_type(Type::SpecialForm(SpecialFormType::Generic))
|
||||||
.write_str("typing.Generic")?;
|
.write_str("typing.Generic")?;
|
||||||
generic_context.display(self.db).fmt_detailed(f)?;
|
generic_context.display(self.db).fmt_detailed(f)?;
|
||||||
|
|
@ -2398,7 +2398,7 @@ impl<'db> FmtDetailed<'db> for DisplayKnownInstanceRepr<'db> {
|
||||||
f.write_char('<')?;
|
f.write_char('<')?;
|
||||||
f.with_type(KnownClass::UnionType.to_class_literal(self.db))
|
f.with_type(KnownClass::UnionType.to_class_literal(self.db))
|
||||||
.write_str("types.UnionType")?;
|
.write_str("types.UnionType")?;
|
||||||
f.write_str(" special form")?;
|
f.write_str(" special-form")?;
|
||||||
if let Ok(ty) = union.union_type(self.db) {
|
if let Ok(ty) = union.union_type(self.db) {
|
||||||
f.write_str(" '")?;
|
f.write_str(" '")?;
|
||||||
ty.display(self.db).fmt_detailed(f)?;
|
ty.display(self.db).fmt_detailed(f)?;
|
||||||
|
|
@ -2408,13 +2408,13 @@ impl<'db> FmtDetailed<'db> for DisplayKnownInstanceRepr<'db> {
|
||||||
}
|
}
|
||||||
KnownInstanceType::Literal(inner) => {
|
KnownInstanceType::Literal(inner) => {
|
||||||
f.set_invalid_syntax();
|
f.set_invalid_syntax();
|
||||||
f.write_str("<special form '")?;
|
f.write_str("<special-form '")?;
|
||||||
inner.inner(self.db).display(self.db).fmt_detailed(f)?;
|
inner.inner(self.db).display(self.db).fmt_detailed(f)?;
|
||||||
f.write_str("'>")
|
f.write_str("'>")
|
||||||
}
|
}
|
||||||
KnownInstanceType::Annotated(inner) => {
|
KnownInstanceType::Annotated(inner) => {
|
||||||
f.set_invalid_syntax();
|
f.set_invalid_syntax();
|
||||||
f.write_str("<special form '")?;
|
f.write_str("<special-form '")?;
|
||||||
f.with_type(Type::SpecialForm(SpecialFormType::Annotated))
|
f.with_type(Type::SpecialForm(SpecialFormType::Annotated))
|
||||||
.write_str("typing.Annotated")?;
|
.write_str("typing.Annotated")?;
|
||||||
f.write_char('[')?;
|
f.write_char('[')?;
|
||||||
|
|
@ -2426,13 +2426,13 @@ impl<'db> FmtDetailed<'db> for DisplayKnownInstanceRepr<'db> {
|
||||||
f.write_char('<')?;
|
f.write_char('<')?;
|
||||||
f.with_type(Type::SpecialForm(SpecialFormType::Callable))
|
f.with_type(Type::SpecialForm(SpecialFormType::Callable))
|
||||||
.write_str("typing.Callable")?;
|
.write_str("typing.Callable")?;
|
||||||
f.write_str(" special form '")?;
|
f.write_str(" special-form '")?;
|
||||||
callable.display(self.db).fmt_detailed(f)?;
|
callable.display(self.db).fmt_detailed(f)?;
|
||||||
f.write_str("'>")
|
f.write_str("'>")
|
||||||
}
|
}
|
||||||
KnownInstanceType::TypeGenericAlias(inner) => {
|
KnownInstanceType::TypeGenericAlias(inner) => {
|
||||||
f.set_invalid_syntax();
|
f.set_invalid_syntax();
|
||||||
f.write_str("<special form '")?;
|
f.write_str("<special-form '")?;
|
||||||
f.with_type(KnownClass::Type.to_class_literal(self.db))
|
f.with_type(KnownClass::Type.to_class_literal(self.db))
|
||||||
.write_str("type")?;
|
.write_str("type")?;
|
||||||
f.write_char('[')?;
|
f.write_char('[')?;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue