Skip to content

Comments

[ty] Added support for "go to definition" for attribute accesses and keyword arguments#19417

Merged
UnboundVariable merged 2 commits intoastral-sh:mainfrom
UnboundVariable:goto_attribute
Jul 18, 2025
Merged

[ty] Added support for "go to definition" for attribute accesses and keyword arguments#19417
UnboundVariable merged 2 commits intoastral-sh:mainfrom
UnboundVariable:goto_attribute

Conversation

@UnboundVariable
Copy link
Collaborator

This PR builds upon #19371. It addresses a few additional code review suggestions and adds support for attribute accesses (expressions of the form x.y) and keyword arguments within call expressions.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 18, 2025

mypy_primer results

No ecosystem changes detected ✅
No memory usage changes detected ✅

@MichaReiser MichaReiser added server Related to the LSP server ty Multi-file analysis & type inference labels Jul 18, 2025
Comment on lines +209 to +210
// Find the call expression that contains this keyword
let module = parsed_module(db, file).load(db);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this seems a bit unfortunate that we need to go and search the covering node again. Would it make sense to instead store the CallExpr in KeywordArgument alongside the keyword?

Getting the function there should be cheaper because CoveringNode allows upward traversal whereas calling covering_node requires an AST traversal

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd advise against doing preemptive micro-optimizations here. This is not a hot code path, so using more memory in an attempt to speed it up is probably not the right tradeoff.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a micro optimization. It just seems unnecessary if we can get this information when extracting the GoToDefinitionTarget. It's right there and I find it even less confusing

@UnboundVariable UnboundVariable merged commit 360eb70 into astral-sh:main Jul 18, 2025
37 checks passed
@UnboundVariable UnboundVariable deleted the goto_attribute branch July 18, 2025 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

server Related to the LSP server ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants