Skip to content

[ty] Semantic tokens: mark comprehension targets as definitions#21636

Merged
MichaReiser merged 1 commit intoastral-sh:mainfrom
lucach:semantic_tokens_comp
Nov 26, 2025
Merged

[ty] Semantic tokens: mark comprehension targets as definitions#21636
MichaReiser merged 1 commit intoastral-sh:mainfrom
lucach:semantic_tokens_comp

Conversation

@lucach
Copy link
Contributor

@lucach lucach commented Nov 26, 2025

Summary

In #21521 I went through all the statements that may introduce names and marked those names as definitions when computing the semantic tokens. However, names can also be introduced by expressions. Some were already covered (lambdas, named expressions), but comprehensions/generators were not. This commit fixes that, and hopefully completes the set of places that can introduce names.

Test Plan

Added a test to check that the targets of list/set/dict comprehensions and generator expressions are marked as definitions.

@astral-sh-bot
Copy link

astral-sh-bot bot commented Nov 26, 2025

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

@astral-sh-bot
Copy link

astral-sh-bot bot commented Nov 26, 2025

mypy_primer results

Changes were detected when running on open source projects
dd-trace-py (https://github.com/DataDog/dd-trace-py)
- ddtrace/appsec/_handlers.py:404:13: error[invalid-argument-type] Argument to bound method `add_configurations` is incorrect: Expected `list[tuple[str, str, str]]`, found `list[Unknown | tuple[str, int, Unknown]] & list[tuple[str, str, str] | tuple[str, int, Unknown]]`
+ ddtrace/appsec/_handlers.py:404:13: error[invalid-argument-type] Argument to bound method `add_configurations` is incorrect: Expected `list[tuple[str, str, str]]`, found `list[tuple[str, str, str] | tuple[str, int, Unknown]] & list[Unknown | tuple[str, int, Unknown]]`

No memory usage changes detected ✅

@AlexWaygood AlexWaygood added server Related to the LSP server ty Multi-file analysis & type inference labels Nov 26, 2025
Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

Thank you

@MichaReiser MichaReiser merged commit b72120f into astral-sh:main Nov 26, 2025
42 checks passed
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