Skip to content
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

Fix overloading with a typevar missing #15320

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

A5rocks
Copy link
Contributor

@A5rocks A5rocks commented May 29, 2023

Resubmitting #11617 cause that was pre-Blackened mypy. Also, that PR probably won't get any eyes anymore.

This fixes #9023. I still need to add a test about this, unfortunately.

@github-actions

This comment has been minimized.

@A5rocks
Copy link
Contributor Author

A5rocks commented May 29, 2023

mypy primer output:

tanjun, this is why I made the change 👍

koda-validate, I literally cannot parse what they're doing with my brain. But it feels like that's this PR messing up, 👎

expression seems like yeah that error is valid, but I don't think the changes made by this PR should reveal that. Or actually I don't know if mypy acknowledges that that error is valid at all, that Type[T1] can be compatible with Callable[..., T2] 😐

for spark I'm not sure if mypy views __argname as pos-only. If it does, this is a bug with this PR :(

steam.py I genuinely dunno, would need to think more about it

discord.py is correct 👍

Anyways, all in all, I think I might need to reconsider some of the changes I made with this PR (I removed something that seemed unnecessary before reviving it) or at least take a good look at some of the failures.

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

Please, don't forget to add tests :)


class A: ...

T = typing.TypeVar("T", bound=A)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I should investigate why current mypy is a-ok without the bound=A here, but errors when it is. That's strange and probably a sign of incorrect special casing: something I hate!

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

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

Tanjun (https://github.com/FasterSpeeding/Tanjun)
+ tanjun/annotations.py:1225: error: Overloaded function implementation does not accept all possible arguments of signature 1  [misc]
+ tanjun/annotations.py:1225: error: Overloaded function implementation cannot produce return type of signature 1  [misc]

vision (https://github.com/pytorch/vision): typechecking got 1.36x slower (39.2s -> 53.2s)
(Performance measurements are based on a single noisy sample)

more-itertools (https://github.com/more-itertools/more-itertools)
+ more_itertools/more.pyi:411: error: Overloaded function signatures 1 and 2 overlap with incompatible return types  [misc]

spark (https://github.com/apache/spark)
+ python/pyspark/sql/functions.py:4640: error: Overloaded function implementation does not accept all possible arguments of signature 2  [misc]
+ python/pyspark/sql/functions.py:9186: error: Overloaded function implementation does not accept all possible arguments of signature 2  [misc]
+ python/pyspark/sql/functions.py:9266: error: Overloaded function implementation does not accept all possible arguments of signature 2  [misc]
+ python/pyspark/sql/functions.py:11102: error: Overloaded function implementation does not accept all possible arguments of signature 2  [misc]

steam.py (https://github.com/Gobot1234/steam.py)
- steam/ext/commands/commands.py:732: error: Overloaded function implementation does not accept all possible arguments of signature 3  [misc]
+ steam/ext/commands/commands.py:732: error: Overloaded function implementation cannot satisfy signature 3 due to inconsistencies in how they use type variables  [misc]
+ steam/ext/commands/commands.py:801: error: Overloaded function implementation cannot satisfy signature 3 due to inconsistencies in how they use type variables  [misc]
+ steam/ext/commands/commands.py:907: error: Overloaded function implementation cannot satisfy signature 3 due to inconsistencies in how they use type variables  [misc]
+ steam/ext/commands/commands.py:974: error: Overloaded function implementation cannot satisfy signature 3 due to inconsistencies in how they use type variables  [misc]
+ steam/ext/commands/commands.py:1080: error: Value of type variable "MC" of "__call__" of "CommandDeco" cannot be "MCD"  [type-var]
+ steam/ext/commands/commands.py:1105: error: Value of type variable "MC" of "__call__" of "CommandDeco" cannot be "MCD"  [type-var]

discord.py (https://github.com/Rapptz/discord.py)
+ discord/ext/commands/core.py:1729: error: Overloaded function signatures 1 and 2 overlap with incompatible return types  [misc]
+ discord/ext/commands/core.py:1799: error: Overloaded function signatures 1 and 2 overlap with incompatible return types  [misc]

@JukkaL
Copy link
Collaborator

JukkaL commented Jul 12, 2023

for spark I'm not sure if mypy views __argname as pos-only. If it does, this is a bug with this PR :(

Yeah, that's how to mark arguments as positional only in older Python versions.

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.

False positive when type checking overloads with generics
3 participants