Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/ty_ide/src/goto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ impl<'db> DefinitionsOrTargets<'db> {
| ty_python_semantic::types::TypeDefinition::Function(definition)
| ty_python_semantic::types::TypeDefinition::TypeVar(definition)
| ty_python_semantic::types::TypeDefinition::TypeAlias(definition)
| ty_python_semantic::types::TypeDefinition::SpecialForm(definition)
| ty_python_semantic::types::TypeDefinition::NewType(definition) => {
ResolvedDefinition::Definition(definition)
}
Expand Down
128 changes: 128 additions & 0 deletions crates/ty_ide/src/goto_type_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,134 @@ mod tests {
");
}

#[test]
fn goto_type_of_typing_dot_literal() {
let test = cursor_test(
r#"
from typing import Literal

a<CURSOR>b = Literal
"#,
);

assert_snapshot!(test.goto_type_definition(), @r"
info[goto-type-definition]: Type definition
--> stdlib/typing.pyi:351:1
|
349 | Final: _SpecialForm
350 |
351 | Literal: _SpecialForm
| ^^^^^^^
352 | TypedDict: _SpecialForm
|
info: Source
--> main.py:4:1
|
2 | from typing import Literal
3 |
4 | ab = Literal
| ^^
|
");
}

// this is a slightly different case to the one above,
// since `Any` is a class in typeshed rather than a variable
#[test]
fn goto_type_of_typing_dot_any() {
let test = cursor_test(
r#"
from typing import Any

a<CURSOR>b = Any
"#,
);

assert_snapshot!(test.goto_type_definition(), @r#"
info[goto-type-definition]: Type definition
--> stdlib/typing.pyi:166:7
|
164 | # from _typeshed import AnnotationForm
165 |
166 | class Any:
| ^^^
167 | """Special type indicating an unconstrained type.
|
info: Source
--> main.py:4:1
|
2 | from typing import Any
3 |
4 | ab = Any
| ^^
|
"#);
}

// Similarly, `Generic` is a `type[]` type in typeshed
#[test]
fn goto_type_of_typing_dot_generic() {
let test = cursor_test(
r#"
from typing import Generic

a<CURSOR>b = Generic
"#,
);

assert_snapshot!(test.goto_type_definition(), @r"
info[goto-type-definition]: Type definition
--> stdlib/typing.pyi:770:1
|
768 | def __class_getitem__(cls, args: TypeVar | tuple[TypeVar, ...]) -> _Final: ...
769 |
770 | Generic: type[_Generic]
| ^^^^^^^
771 |
772 | class _ProtocolMeta(ABCMeta):
|
info: Source
--> main.py:4:1
|
2 | from typing import Generic
3 |
4 | ab = Generic
| ^^
|
");
}

#[test]
fn goto_type_of_ty_extensions_special_form() {
let test = cursor_test(
r#"
from ty_extensions import AlwaysTruthy

a<CURSOR>b = AlwaysTruthy
"#,
);

assert_snapshot!(test.goto_type_definition(), @r"
info[goto-type-definition]: Type definition
--> stdlib/ty_extensions.pyi:21:1
|
19 | # Types
20 | Unknown = object()
21 | AlwaysTruthy = object()
| ^^^^^^^^^^^^
22 | AlwaysFalsy = object()
|
info: Source
--> main.py:4:1
|
2 | from ty_extensions import AlwaysTruthy
3 |
4 | ab = AlwaysTruthy
| ^^
|
");
}

#[test]
fn goto_type_of_expression_with_function_type() {
let test = cursor_test(
Expand Down
209 changes: 209 additions & 0 deletions crates/ty_ide/src/inlay_hints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,25 @@ mod tests {
w[: int] = z

---------------------------------------------
info[inlay-hint-location]: Inlay Hint Target
--> stdlib/typing.pyi:351:1
|
349 | Final: _SpecialForm
350 |
351 | Literal: _SpecialForm
| ^^^^^^^
352 | TypedDict: _SpecialForm
|
info: Source
--> main2.py:6:5
|
5 | x = 1
6 | y[: Literal[1]] = x
| ^^^^^^^
7 | z[: int] = i(1)
8 | w[: int] = z
|

info[inlay-hint-location]: Inlay Hint Target
--> stdlib/builtins.pyi:348:7
|
Expand Down Expand Up @@ -668,6 +687,44 @@ mod tests {
x4[: int], y4[: str] = (x3, y3)

---------------------------------------------
info[inlay-hint-location]: Inlay Hint Target
--> stdlib/typing.pyi:351:1
|
349 | Final: _SpecialForm
350 |
351 | Literal: _SpecialForm
| ^^^^^^^
352 | TypedDict: _SpecialForm
|
info: Source
--> main2.py:8:6
|
7 | x1, y1 = (1, 'abc')
8 | x2[: Literal[1]], y2[: Literal["abc"]] = (x1, y1)
| ^^^^^^^
9 | x3[: int], y3[: str] = (i(1), s('abc'))
10 | x4[: int], y4[: str] = (x3, y3)
|

info[inlay-hint-location]: Inlay Hint Target
--> stdlib/typing.pyi:351:1
|
349 | Final: _SpecialForm
350 |
351 | Literal: _SpecialForm
| ^^^^^^^
352 | TypedDict: _SpecialForm
|
info: Source
--> main2.py:8:24
|
7 | x1, y1 = (1, 'abc')
8 | x2[: Literal[1]], y2[: Literal["abc"]] = (x1, y1)
| ^^^^^^^
9 | x3[: int], y3[: str] = (i(1), s('abc'))
10 | x4[: int], y4[: str] = (x3, y3)
|

info[inlay-hint-location]: Inlay Hint Target
--> stdlib/builtins.pyi:348:7
|
Expand Down Expand Up @@ -772,6 +829,44 @@ mod tests {
x4[: int], y4[: str] = x3, y3

---------------------------------------------
info[inlay-hint-location]: Inlay Hint Target
--> stdlib/typing.pyi:351:1
|
349 | Final: _SpecialForm
350 |
351 | Literal: _SpecialForm
| ^^^^^^^
352 | TypedDict: _SpecialForm
|
info: Source
--> main2.py:8:6
|
7 | x1, y1 = 1, 'abc'
8 | x2[: Literal[1]], y2[: Literal["abc"]] = x1, y1
| ^^^^^^^
9 | x3[: int], y3[: str] = i(1), s('abc')
10 | x4[: int], y4[: str] = x3, y3
|

info[inlay-hint-location]: Inlay Hint Target
--> stdlib/typing.pyi:351:1
|
349 | Final: _SpecialForm
350 |
351 | Literal: _SpecialForm
| ^^^^^^^
352 | TypedDict: _SpecialForm
|
info: Source
--> main2.py:8:24
|
7 | x1, y1 = 1, 'abc'
8 | x2[: Literal[1]], y2[: Literal["abc"]] = x1, y1
| ^^^^^^^
9 | x3[: int], y3[: str] = i(1), s('abc')
10 | x4[: int], y4[: str] = x3, y3
|

info[inlay-hint-location]: Inlay Hint Target
--> stdlib/builtins.pyi:348:7
|
Expand Down Expand Up @@ -876,6 +971,44 @@ mod tests {
w[: tuple[int, str]] = z

---------------------------------------------
info[inlay-hint-location]: Inlay Hint Target
--> stdlib/typing.pyi:351:1
|
349 | Final: _SpecialForm
350 |
351 | Literal: _SpecialForm
| ^^^^^^^
352 | TypedDict: _SpecialForm
|
info: Source
--> main2.py:8:11
|
7 | x = (1, 'abc')
8 | y[: tuple[Literal[1], Literal["abc"]]] = x
| ^^^^^^^
9 | z[: tuple[int, str]] = (i(1), s('abc'))
10 | w[: tuple[int, str]] = z
|

info[inlay-hint-location]: Inlay Hint Target
--> stdlib/typing.pyi:351:1
|
349 | Final: _SpecialForm
350 |
351 | Literal: _SpecialForm
| ^^^^^^^
352 | TypedDict: _SpecialForm
|
info: Source
--> main2.py:8:23
|
7 | x = (1, 'abc')
8 | y[: tuple[Literal[1], Literal["abc"]]] = x
| ^^^^^^^
9 | z[: tuple[int, str]] = (i(1), s('abc'))
10 | w[: tuple[int, str]] = z
|

info[inlay-hint-location]: Inlay Hint Target
--> stdlib/builtins.pyi:348:7
|
Expand Down Expand Up @@ -978,6 +1111,63 @@ mod tests {
x3[: int], (y3[: str], z3[: int]) = (i(1), (s('abc'), i(2)))
x4[: int], (y4[: str], z4[: int]) = (x3, (y3, z3))
---------------------------------------------
info[inlay-hint-location]: Inlay Hint Target
--> stdlib/typing.pyi:351:1
|
349 | Final: _SpecialForm
350 |
351 | Literal: _SpecialForm
| ^^^^^^^
352 | TypedDict: _SpecialForm
|
info: Source
--> main2.py:8:6
|
7 | x1, (y1, z1) = (1, ('abc', 2))
8 | x2[: Literal[1]], (y2[: Literal["abc"]], z2[: Literal[2]]) = (x1, (y1, z1))
| ^^^^^^^
9 | x3[: int], (y3[: str], z3[: int]) = (i(1), (s('abc'), i(2)))
10 | x4[: int], (y4[: str], z4[: int]) = (x3, (y3, z3))
|

info[inlay-hint-location]: Inlay Hint Target
--> stdlib/typing.pyi:351:1
|
349 | Final: _SpecialForm
350 |
351 | Literal: _SpecialForm
| ^^^^^^^
352 | TypedDict: _SpecialForm
|
info: Source
--> main2.py:8:25
|
7 | x1, (y1, z1) = (1, ('abc', 2))
8 | x2[: Literal[1]], (y2[: Literal["abc"]], z2[: Literal[2]]) = (x1, (y1, z1))
| ^^^^^^^
9 | x3[: int], (y3[: str], z3[: int]) = (i(1), (s('abc'), i(2)))
10 | x4[: int], (y4[: str], z4[: int]) = (x3, (y3, z3))
|

info[inlay-hint-location]: Inlay Hint Target
--> stdlib/typing.pyi:351:1
|
349 | Final: _SpecialForm
350 |
351 | Literal: _SpecialForm
| ^^^^^^^
352 | TypedDict: _SpecialForm
|
info: Source
--> main2.py:8:47
|
7 | x1, (y1, z1) = (1, ('abc', 2))
8 | x2[: Literal[1]], (y2[: Literal["abc"]], z2[: Literal[2]]) = (x1, (y1, z1))
| ^^^^^^^
9 | x3[: int], (y3[: str], z3[: int]) = (i(1), (s('abc'), i(2)))
10 | x4[: int], (y4[: str], z4[: int]) = (x3, (y3, z3))
|

info[inlay-hint-location]: Inlay Hint Target
--> stdlib/builtins.pyi:348:7
|
Expand Down Expand Up @@ -1113,6 +1303,25 @@ mod tests {
z: int = i(1)
w[: int] = z
---------------------------------------------
info[inlay-hint-location]: Inlay Hint Target
--> stdlib/typing.pyi:351:1
|
349 | Final: _SpecialForm
350 |
351 | Literal: _SpecialForm
| ^^^^^^^
352 | TypedDict: _SpecialForm
|
info: Source
--> main2.py:6:5
|
5 | x: int = 1
6 | y[: Literal[1]] = x
| ^^^^^^^
7 | z: int = i(1)
8 | w[: int] = z
|

info[inlay-hint-location]: Inlay Hint Target
--> stdlib/builtins.pyi:348:7
|
Expand Down
Loading
Loading