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 functools.partial with Union of Any #17283

Closed
wants to merge 1 commit into from

Conversation

cdce8p
Copy link
Collaborator

@cdce8p cdce8p commented May 24, 2024

Fixes

from functools import partial
from typing import Any

cls1: Any | Any
partial(cls1, 2)  # error: "Any | Any" not callable

@cdce8p cdce8p added topic-plugins The plugin API and ideas for new plugins false-positive mypy gave an error on correct code labels May 24, 2024
@cdce8p cdce8p requested a review from hauntsaninja May 24, 2024 10:47
Copy link
Contributor

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

kopf (https://github.com/nolar/kopf)
- kopf/_core/actions/invocation.py:127: error: Incompatible types in assignment (expression has type "partial[partial[object | Coroutine[None, None, object]]]", variable has type "partial[object | Coroutine[None, None, object | None] | None]")  [assignment]
+ kopf/_core/actions/invocation.py:127: error: Incompatible types in assignment (expression has type "partial[partial[object | Coroutine[None, None, object]]]", variable has type "partial[object | Coroutine[None, None, object]]")  [assignment]
- kopf/_core/actions/invocation.py:127: error: Argument 1 to "run" of "Context" has incompatible type "partial[object | Coroutine[None, None, object | None] | None]"; expected "Callable[[VarArg(Any), KwArg(Any)], partial[object | Coroutine[None, None, object]]]"  [arg-type]
+ kopf/_core/actions/invocation.py:127: error: Argument 1 to "run" of "Context" has incompatible type "partial[object | Coroutine[None, None, object]]"; expected "Callable[[VarArg(Any), KwArg(Any)], partial[object | Coroutine[None, None, object]]]"  [arg-type]
- kopf/_core/actions/invocation.py:127: note: "partial[object | Coroutine[None, None, object | None] | None].__call__" has type "Callable[[VarArg(Any), KwArg(Any)], object | Coroutine[None, None, object | None] | None]"
+ kopf/_core/actions/invocation.py:127: note: "partial[object | Coroutine[None, None, object]].__call__" has type "Callable[[VarArg(Any), KwArg(Any)], object | Coroutine[None, None, object]]"

@hauntsaninja
Copy link
Collaborator

Nice, thanks for finding! expandtype is a little interesting to me here, since there isn't a type variable mapping. I think maybe we just want to more explicitly handle unions... I opened #17284 , let me know what you think :-)

@cdce8p
Copy link
Collaborator Author

cdce8p commented May 25, 2024

Fixed in #17284

@cdce8p cdce8p closed this May 25, 2024
@cdce8p cdce8p deleted the functools-union branch May 25, 2024 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
false-positive mypy gave an error on correct code topic-plugins The plugin API and ideas for new plugins
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants