-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Reconsider constraints involving parameter specifications #15272
Conversation
This comment has been minimized.
This comment has been minimized.
Mypy primer diff looks right! |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one quick comment
This comment has been minimized.
This comment has been minimized.
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 :( |
This comment has been minimized.
This comment has been minimized.
@@ -79,15 +79,19 @@ def __repr__(self) -> str: | |||
op_str = "<:" | |||
if self.op == SUPERTYPE_OF: | |||
op_str = ":>" | |||
return f"{self.type_var} {op_str} {self.target}" | |||
return f"{self.origin_type_var} {op_str} {self.target}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too sure why this was this way before and if this is entirely bad behavior. I added this (and updates to hashing and equality) because paramspec types have extra state that is important: their prefix (which Concatenate
adds)
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]
|
Hi, bumping for @hauntsaninja or maybe @JukkaL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks great! Might be worth a follow up PR to see if we can deduplicate a little bit or factor some stuff out of visit_instance
|
||
# I don't think we can parametrize... | ||
for direction in (SUPERTYPE_OF, SUBTYPE_OF): | ||
print(f"direction is {direction}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: stray print
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh oops, lol.
Err wait, IIRC that's in order to make any test failures easier to check (it'll only show stdout on test failure).
I am going to revert this. IMO this is just a bunch of more hacks to compensate for older hacks. Current |
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) |
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. |
Concatenate
return value #15073Concatenate
return value #15086Yet another part of #14903 that's finally been extracted!