Skip to content

Fix special cases of kwargs + TypeVarTuple - #17512

Closed
A5rocks wants to merge 14 commits into
python:masterfrom
A5rocks:kwargs-and-tvt
Closed

A5rocks wants to merge 14 commits into
python:masterfrom
A5rocks:kwargs-and-tvt

Conversation

@A5rocks

@A5rocks A5rocks commented Jul 10, 2024 •

Copy link
Copy Markdown
Collaborator

Fixes #16522. This PR adds special casing for TypeVarTuple inference in the face of kwargs, though I believe the general case requires providing multiple possible constraints (e.g. "constraint a OR constraint b OR constraint C") which either isn't possible or I don't know how to.

This PR also fixes the subtyping of e.g. def f(a: int) -> None being a subtype of def g(*args: Unpack[tuple[Any, ...]]).

TODO:

Comment thread mypy/test/testtypes.py Outdated
@A5rocks

A5rocks commented Jul 10, 2024

Copy link
Copy Markdown
Collaborator Author

cc @ilevkivskyi since I saw your changes w/r/t typevartuples when glancing over the merge conflicts. Maybe you'll have an idea of whether this Any-tuple thing is worth anything.

@A5rocks A5rocks changed the title Introduce Any-tuple and Introduce Any-tuple and special cases of kwargs + TypeVarTuple Jul 10, 2024
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@A5rocks A5rocks changed the title Introduce Any-tuple and special cases of kwargs + TypeVarTuple Fix special cases of kwargs + TypeVarTuple Aug 27, 2024
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@jakkdl

jakkdl commented Sep 17, 2024

Copy link
Copy Markdown

With the simplification from removing Any-tuple this looks pretty damn clean. With no diff from mypy_primer I think we only need new tests and then it's pretty much ready to merge 🎉

@A5rocks

A5rocks commented Sep 27, 2024 •

Copy link
Copy Markdown
Collaborator Author

I split off #17843 for the part of this PR I am certain is correct. I have some ideas on how to fix kwargs's presence with TypeVarTuple in the general case that I want to try out.

Turns out I can't split anything off because the two fixes need each other for any visible effect.

@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@jakkdl

jakkdl commented Mar 31, 2025

Copy link
Copy Markdown

Would be lovely to get this merged, but it appears we've gotten merge conflicts that need resolved @A5rocks

@A5rocks

A5rocks commented Apr 23, 2025

Copy link
Copy Markdown
Collaborator Author

I've made a better version of this at #18958

@A5rocks A5rocks closed this Apr 23, 2025
@A5rocks
A5rocks deleted the kwargs-and-tvt branch October 22, 2025 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Callables like operator.call produce arg-type error with callables that take *args: Unpack[Ts] and >= 1 keyword argument Never inferred in complex situation with variadic callable protocol

3 participants