mypy icon indicating copy to clipboard operation
mypy copied to clipboard

Fix overloading with a typevar missing

Open A5rocks opened this issue 1 year ago • 4 comments

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.

A5rocks avatar May 29 '23 07:05 A5rocks

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]

koda-validate (https://github.com/keithasaurus/koda-validate)
+ koda_validate/dictionary.py:683: error: Overloaded function implementation does not accept all possible arguments of signature 1  [misc]
+ koda_validate/dictionary.py:683: error: Overloaded function implementation does not accept all possible arguments of signature 2  [misc]
+ koda_validate/dictionary.py:683: error: Overloaded function implementation does not accept all possible arguments of signature 3  [misc]
+ koda_validate/dictionary.py:683: error: Overloaded function implementation does not accept all possible arguments of signature 4  [misc]
+ koda_validate/dictionary.py:683: error: Overloaded function implementation does not accept all possible arguments of signature 5  [misc]
+ koda_validate/dictionary.py:683: error: Overloaded function implementation does not accept all possible arguments of signature 6  [misc]
+ koda_validate/dictionary.py:683: error: Overloaded function implementation does not accept all possible arguments of signature 7  [misc]
+ koda_validate/dictionary.py:683: error: Overloaded function implementation does not accept all possible arguments of signature 8  [misc]
+ koda_validate/dictionary.py:683: error: Overloaded function implementation does not accept all possible arguments of signature 9  [misc]
+ koda_validate/dictionary.py:683: error: Overloaded function implementation does not accept all possible arguments of signature 10  [misc]
+ koda_validate/dictionary.py:683: error: Overloaded function implementation does not accept all possible arguments of signature 11  [misc]
+ koda_validate/dictionary.py:683: error: Overloaded function implementation does not accept all possible arguments of signature 12  [misc]
+ koda_validate/dictionary.py:683: error: Overloaded function implementation does not accept all possible arguments of signature 13  [misc]
+ koda_validate/dictionary.py:683: error: Overloaded function implementation does not accept all possible arguments of signature 14  [misc]
+ koda_validate/dictionary.py:683: error: Overloaded function implementation does not accept all possible arguments of signature 15  [misc]
+ koda_validate/dictionary.py:683: error: Overloaded function implementation does not accept all possible arguments of signature 16  [misc]

Expression (https://github.com/cognitedata/Expression)
+ expression/extra/result/catch.py:15: error: Overloaded function signatures 1 and 2 overlap with incompatible return types  [misc]

spark (https://github.com/apache/spark)
+ python/pyspark/sql/functions.py:3683: error: Overloaded function implementation does not accept all possible arguments of signature 2  [misc]
+ python/pyspark/sql/functions.py:7183: error: Overloaded function implementation does not accept all possible arguments of signature 2  [misc]
+ python/pyspark/sql/functions.py:7263: error: Overloaded function implementation does not accept all possible arguments of signature 2  [misc]
+ python/pyspark/sql/functions.py:9099: 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:907: 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:1721: error: Overloaded function signatures 1 and 2 overlap with incompatible return types  [misc]
+ discord/ext/commands/core.py:1791: error: Overloaded function signatures 1 and 2 overlap with incompatible return types  [misc]

github-actions[bot] avatar May 29 '23 07:05 github-actions[bot]

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.

A5rocks avatar May 29 '23 07:05 A5rocks

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

koda-validate (https://github.com/keithasaurus/koda-validate)
+ koda_validate/dictionary.py:683: error: Overloaded function implementation does not accept all possible arguments of signature 1  [misc]
+ koda_validate/dictionary.py:683: error: Overloaded function implementation does not accept all possible arguments of signature 2  [misc]
+ koda_validate/dictionary.py:683: error: Overloaded function implementation does not accept all possible arguments of signature 3  [misc]
+ koda_validate/dictionary.py:683: error: Overloaded function implementation does not accept all possible arguments of signature 4  [misc]
+ koda_validate/dictionary.py:683: error: Overloaded function implementation does not accept all possible arguments of signature 5  [misc]
+ koda_validate/dictionary.py:683: error: Overloaded function implementation does not accept all possible arguments of signature 6  [misc]
+ koda_validate/dictionary.py:683: error: Overloaded function implementation does not accept all possible arguments of signature 7  [misc]
+ koda_validate/dictionary.py:683: error: Overloaded function implementation does not accept all possible arguments of signature 8  [misc]
+ koda_validate/dictionary.py:683: error: Overloaded function implementation does not accept all possible arguments of signature 9  [misc]
+ koda_validate/dictionary.py:683: error: Overloaded function implementation does not accept all possible arguments of signature 10  [misc]
+ koda_validate/dictionary.py:683: error: Overloaded function implementation does not accept all possible arguments of signature 11  [misc]
+ koda_validate/dictionary.py:683: error: Overloaded function implementation does not accept all possible arguments of signature 12  [misc]
+ koda_validate/dictionary.py:683: error: Overloaded function implementation does not accept all possible arguments of signature 13  [misc]
+ koda_validate/dictionary.py:683: error: Overloaded function implementation does not accept all possible arguments of signature 14  [misc]
+ koda_validate/dictionary.py:683: error: Overloaded function implementation does not accept all possible arguments of signature 15  [misc]
+ koda_validate/dictionary.py:683: error: Overloaded function implementation does not accept all possible arguments of signature 16  [misc]

Expression (https://github.com/cognitedata/Expression)
+ expression/extra/result/catch.py:15: error: Overloaded function signatures 1 and 2 overlap with incompatible return types  [misc]

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]

graphql-core (https://github.com/graphql-python/graphql-core) got 1.07x slower (279.9s -> 300.1s)

spark (https://github.com/apache/spark)
+ python/pyspark/sql/functions.py:4205: error: Overloaded function implementation does not accept all possible arguments of signature 2  [misc]
+ python/pyspark/sql/functions.py:8561: error: Overloaded function implementation does not accept all possible arguments of signature 2  [misc]
+ python/pyspark/sql/functions.py:8641: error: Overloaded function implementation does not accept all possible arguments of signature 2  [misc]
+ python/pyspark/sql/functions.py:10477: 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:907: 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]

github-actions[bot] avatar Jun 14 '23 23:06 github-actions[bot]

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]

github-actions[bot] avatar Jun 18 '23 01:06 github-actions[bot]

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.

JukkaL avatar Jul 12 '23 12:07 JukkaL