-
-
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
Unable to use @overload with Concatenate decorator #12716
Comments
Code to reproduce is at: https://github.com/aio-libs/aiomcache/blob/master/aiomcache/client.py#L159 |
Note after #15898 is merged, you should be able to either:
|
Fixes #15737 Fixes #12844 Fixes #12716 My goal was to fix the `ParamSpec` issues, but it turns out decorated overloads were not supported at all. Namely: * Decorators on overload items were ignored, caller would see original undecorated item types * Overload item overlap checks were performed for original types, while arguably we should use decorated types * Overload items completeness w.r.t. to implementation was checked with decorated implementation, and undecorated items Here I add basic support using same logic as for regular decorated functions: initially set type to `None` and defer callers until definition is type-checked. Note this results in few more `Cannot determine type` in case of other errors, but I think it is fine. Note I also add special-casing for "inline" applications of generic functions to overload arguments. This use case was mentioned few times alongside overloads. The general fix would be tricky, and my special-casing should cover typical use cases. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
First option works. But, I don't understand how to do the second option. Looks like your tests do the former, so I guess I'll stick with that. |
I meant something using callback protocols (that allow specifying argument names unlike simple class WithConn(Protocol[_P, _R]):
def __call__(s, self: Any, conn: str, *args: _P.args, **kwargs: _P.kwargs) -> _R: ...
class NoConn(Protocol[_P, _R]):
def __call__(s, self: Any, *args: _P.args, **kwargs: _P.kwargs) -> _R: ...
def acquire(func: WithConn[_P, _T]) -> NoConn[_P, _T]:
... But I just tried and it looks like it doesn't really work because of some unrelated bug with return type checks for generic overloads. |
Not sure if there's something I'm doing wrong, but seem to have encountered a regression that's breaking this again in 1.7: #16481 |
Bug Report
I can't seem to figure out any way to get
@overload
s to work with a method being transformed by a decorator.To Reproduce
I've attempted to reduce it to a small example:
I have experimented with adding/removing
conn
from the overloads and adding/moving the @acquire at various locations.Expected Behavior
The final call to work correctly with no errors in mypy.
Actual Behavior
Depending on exactly how I write it, I end up with either complaints about the definition (e.g.
Overloaded function implementation does not accept all possible arguments of signature 1
) or complaints about the final call (e.g.No overload variant of "get" matches argument type "bytes"
).Your Environment
The text was updated successfully, but these errors were encountered: