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
2 changes: 1 addition & 1 deletion crates/ty_ide/src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4025,7 +4025,7 @@ quux.<CURSOR>
__module__ :: str
__mul__ :: bound method Quux.__mul__(value: SupportsIndex, /) -> tuple[int | str, ...]
__ne__ :: bound method Quux.__ne__(value: object, /) -> bool
__new__ :: (x: int, y: str) -> None
__new__ :: (x: int, y: str) -> Quux
__orig_bases__ :: tuple[Any, ...]
__reduce__ :: bound method Quux.__reduce__() -> str | tuple[Any, ...]
__reduce_ex__ :: bound method Quux.__reduce_ex__(protocol: SupportsIndex, /) -> str | tuple[Any, ...]
Expand Down
38 changes: 38 additions & 0 deletions crates/ty_ide/src/goto_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1708,6 +1708,44 @@ class Foo(type("Ba<CURSOR>r", (), {})):
assert_snapshot!(test.goto_definition(), @"No goto target found");
}

/// goto-definition on a dynamic namedtuple class literal (created via `collections.namedtuple()`)
#[test]
fn goto_definition_dynamic_namedtuple_literal() {
let test = CursorTest::builder()
.source(
"main.py",
r#"
from collections import namedtuple

Point = namedtuple("Point", ["x", "y"])

p = Poi<CURSOR>nt(1, 2)
"#,
)
.build();

assert_snapshot!(test.goto_definition(), @r#"
info[goto-definition]: Go to definition
--> main.py:6:5
|
4 | Point = namedtuple("Point", ["x", "y"])
5 |
6 | p = Point(1, 2)
| ^^^^^ Clicking here
|
info: Found 1 definition
--> main.py:4:1
|
2 | from collections import namedtuple
3 |
4 | Point = namedtuple("Point", ["x", "y"])
| -----
5 |
6 | p = Point(1, 2)
|
"#);
}

// TODO: Should only list `a: int`
#[test]
fn redeclarations() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Unsupported special types

We do not understand the functional syntax for creating `NamedTuple`s, `TypedDict`s or `Enum`s yet.
But we also do not emit false positives when these are used in type expressions.
We do not understand the functional syntax for creating `TypedDict`s or `Enum`s yet. But we also do
not emit false positives when these are used in type expressions.

```py
import collections
Expand All @@ -11,8 +11,6 @@ import typing
MyEnum = enum.Enum("MyEnum", ["foo", "bar", "baz"])
MyIntEnum = enum.IntEnum("MyIntEnum", ["foo", "bar", "baz"])
MyTypedDict = typing.TypedDict("MyTypedDict", {"foo": int})
MyNamedTuple1 = typing.NamedTuple("MyNamedTuple1", [("foo", int)])
MyNamedTuple2 = collections.namedtuple("MyNamedTuple2", ["foo"])

def f(a: MyEnum, b: MyTypedDict, c: MyNamedTuple1, d: MyNamedTuple2): ...
def f(a: MyEnum, b: MyTypedDict): ...
```
Loading
Loading