Skip to content

Fix generator expressions in typed list literals - #11950

Open
Guishi Wang (guishiw) wants to merge 1 commit into
microsoft:mainfrom
guishiw:fix/11841-generator-context
Open

Guishi Wang (guishiw) wants to merge 1 commit into
microsoft:mainfrom
guishiw:fix/11841-generator-context

Conversation

@guishiw

Copy link
Copy Markdown

fix: #11841

Root cause
The expected-type path for list and set literals treated every comprehension parse node as a container comprehension. A parenthesized generator expression uses the same parse-node kind, so Pyright checked its yielded element type instead of checking the generator object as a list element.

Fix strategy
Exclude generator expressions from the comprehension-specific expected-type path and evaluate them as ordinary expressions. Add a regression case to the existing list literal sample.

The relevant test suite passes with 176 tests.

@heejaechang

Copy link
Copy Markdown
Collaborator

🟢 Pyright CLI QA — c1d28c5d — verdict: green

Automated CLI checks compared this change with its base revision.
5 focused check(s) completed.

No new behavior difference was detected.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to correctly identify the generator

2 participants