mypy icon indicating copy to clipboard operation
mypy copied to clipboard

Reconsider constraints involving parameter specifications

Open A5rocks opened this issue 2 years ago • 7 comments

  • Fixes https://github.com/python/mypy/issues/15037
  • Fixes https://github.com/python/mypy/issues/15065
  • Fixes https://github.com/python/mypy/issues/15073
  • Fixes https://github.com/python/mypy/issues/15388
  • Fixes https://github.com/python/mypy/issues/15086

Yet another part of https://github.com/python/mypy/pull/14903 that's finally been extracted!

A5rocks avatar May 19 '23 22:05 A5rocks

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

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 19 '23 22:05 github-actions[bot]

Mypy primer diff looks right!

A5rocks avatar May 20 '23 01:05 A5rocks

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

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 Jul 02 '23 04:07 github-actions[bot]

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

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 Jul 07 '23 04:07 github-actions[bot]

Fake error

Decently close to coming up with a reliable way to trigger this logic, but funnily enough I found a paramspec bug 👻

Just marking it here before I forget:

from typing import Generic, Callable, Union
from typing_extensions import ParamSpec, Concatenate

P = ParamSpec("P")
P1 = ParamSpec("P1")

class Tester(Generic[P1]):
    @staticmethod
    def test_something(x: Callable[P, None]) -> Tester[P]: ...  # type: ignore[empty-body]

    @staticmethod
    def test_concatenate(x: Callable[P, None]) -> Tester[Concatenate[int, P]]: ... # type: ignore[empty-body]

def func(
    action: Callable[P, None],
) -> None:
    job = Tester.test_concatenate(action) if True else Tester.test_something(action)
    reveal_type(job)

err, actually i'm decently sure that's just inference being annoying :(

A5rocks avatar Jul 07 '23 04:07 A5rocks

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

graphql-core (https://github.com/graphql-python/graphql-core): typechecking got 1.05x slower (315.7s -> 332.7s)
(Performance measurements are based on a single noisy sample)

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 Jul 07 '23 06:07 github-actions[bot]

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

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 Jul 08 '23 02:07 github-actions[bot]

Hi, bumping for @hauntsaninja or maybe @JukkaL.

A5rocks avatar Aug 09 '23 06:08 A5rocks

I am going to revert this. IMO this is just a bunch of more hacks to compensate for older hacks. Current ParamSpec support is quite foundationally broken. That needs to be addressed first.

ilevkivskyi avatar Aug 09 '23 06:08 ilevkivskyi

I do think this isn't necessarily hacky -- I basically updated the code directly based on how I expect things to work out.... but I understand that ParamSpec support as a whole is hacky so... Makes sense

(I'm still surprised that this solved any issues at all; I made this PR because things were being weird)

A5rocks avatar Aug 09 '23 07:08 A5rocks

Yes, right, this doesn't really adds new hacks. I think I have an idea how to make ParamSpec a bit more principled. I am going to include some part of cleanups in coming inference PR (just because I was touching related code). Then I will make a separate second PR. I see you are interested in this topic. I will keep you posted on Discord.

ilevkivskyi avatar Aug 09 '23 08:08 ilevkivskyi