Skip to content

Infer list[T] for starred target in unpacking - #18401

Merged
dhruvmanila merged 1 commit into
mainfrom
dhruv/starred-unpacking-list
Jun 3, 2025
Merged

dhruvmanila merged 1 commit into
mainfrom
dhruv/starred-unpacking-list

Conversation

@dhruvmanila

Copy link
Copy Markdown
Member

Summary

Closes: astral-sh/ty#191

Test Plan

Update existing tests.

@dhruvmanila dhruvmanila added the ty The ty type checker label May 31, 2025
@github-actions

github-actions Bot commented May 31, 2025 •

Copy link
Copy Markdown
Contributor

mypy_primer results

No ecosystem changes detected ✅

@dhruvmanila
dhruvmanila force-pushed the dhruv/starred-unpacking-list branch from 3092eda to 3e81edc Compare May 31, 2025 09:26

@dcreager dcreager left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice!

@dhruvmanila
dhruvmanila merged commit 2289187 into main Jun 3, 2025
@dhruvmanila
dhruvmanila deleted the dhruv/starred-unpacking-list branch June 3, 2025 01:55
dhruvmanila added a commit that referenced this pull request Jun 3, 2025
## Summary

Follow-up from #18401, I was looking at whether that would fix the issue
at astral-sh/ty#247 (comment)
and it didn't, which made me realize that the PR only inferred `list[T]`
when the value type was tuple but it could be other types as well.

This PR fixes the actual issue by inferring `list[T]` for the non-tuple
type case.

## Test Plan

Add test cases for starred expression involved with non-tuple type. I
also added a few test cases for list type and list literal.

I also verified that the example in the linked issue comment works:
```py
def _(line: str):
    a, b, *c = line.split(maxsplit=2)
    c.pop()
```
dcreager added a commit that referenced this pull request Jun 3, 2025
…aration

* origin/main:
  [ty] Infer `list[T]` when unpacking non-tuple type (#18438)
  [ty] Meta-type of type variables should be type[..] (#18439)
  [`pyupgrade`] Make fix unsafe if it deletes comments (`UP050`) (#18390)
  [`pyupgrade`] Make fix unsafe if it deletes comments (`UP004`) (#18393)
  [ty] Support using legacy typing aliases for generic classes in type annotations (#18404)
  Use ty's completions in playground (#18425)
  Update editor setup docs about Neovim and Vim (#18324)
  Update NPM Development dependencies (#18423)
  Infer `list[T]` for starred target in unpacking (#18401)
  [`refurb`] Mark `FURB180` fix unsafe when class has bases (#18149)
  [`fastapi`] Avoid false positive for class dependencies (`FAST003`) (#18271)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty The ty type checker

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Combine starred element types in unpacking

2 participants