Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix type extraction from isinstance checks #19223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

sterliakov
Copy link
Collaborator

Fixes #19221. Instead of trying to use the first (maybe) overload item and erase it, just use the underlying type with Any-filled typevars

This comment has been minimized.

@sterliakov sterliakov marked this pull request as draft June 4, 2025 01:18
Copy link
Contributor

github-actions bot commented Jun 4, 2025

Diff from mypy_primer, showing the effect of this PR on open source code:

antidote (https://github.com/Finistere/antidote): 1.44x slower (63.3s -> 91.3s in single noisy sample)

ibis (https://github.com/ibis-project/ibis)
- ibis/formats/pandas.py:71: error: Incompatible types in assignment (expression has type "list[float]", variable has type "Series[Any] | Iterable[tuple[str, dtype[Any] | ExtensionDtype]]")  [assignment]
- ibis/legacy/udf/vectorized.py:174: error: Argument 1 to "len" has incompatible type "float"; expected "Sized"  [arg-type]

pandas (https://github.com/pandas-dev/pandas)
+ pandas/core/algorithms.py:219: error: Unused "type: ignore" comment  [unused-ignore]
+ pandas/core/arrays/datetimes.py:334: error: Unused "type: ignore" comment  [unused-ignore]

materialize (https://github.com/MaterializeInc/materialize): 1.06x slower (132.1s -> 139.8s in single noisy sample)

janus (https://github.com/aio-libs/janus): 7.79x slower (0.9s -> 6.8s in single noisy sample)

mypy (https://github.com/python/mypy): 1.07x slower (94.5s -> 101.3s in single noisy sample)

spark (https://github.com/apache/spark)
- python/pyspark/pandas/typedef/typehints.py:670: error: Incompatible types in assignment (expression has type "type[float64] | Any", variable has type "type[NameTypeHolder]")  [assignment]
- python/pyspark/pandas/typedef/typehints.py:834: error: Incompatible types in assignment (expression has type "type[float64] | Any", variable has type "None")  [assignment]
+ python/pyspark/pandas/typedef/typehints.py:834: error: Incompatible types in assignment (expression has type "type[Any] | Any", variable has type "None")  [assignment]
- python/pyspark/pandas/typedef/typehints.py:847: error: Incompatible types in assignment (expression has type "type[float64] | Any", variable has type "None")  [assignment]
+ python/pyspark/pandas/typedef/typehints.py:847: error: Incompatible types in assignment (expression has type "type[Any] | Any", variable has type "None")  [assignment]

imagehash (https://github.com/JohannesBuchner/imagehash): 1.06x slower (79.2s -> 84.3s in single noisy sample)

discord.py (https://github.com/Rapptz/discord.py): 1.08x faster (299.0s -> 276.0s in single noisy sample)

@sterliakov sterliakov marked this pull request as ready for review June 4, 2025 02:18
@sterliakov
Copy link
Collaborator Author

Primer hits look correct, that's a few more false positives fixed.

@sterliakov sterliakov requested a review from ilevkivskyi June 4, 2025 11:59
Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

Nice to have this fixed!

@JukkaL JukkaL merged commit ce6355e into python:master Jun 5, 2025
19 checks passed
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.

Specifying self-type for first __init__ overload affects isinstance type narrowing
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.