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 explicit type for partial #17424

Merged
merged 3 commits into from
Jun 23, 2024
Merged

Conversation

ilevkivskyi
Copy link
Member

This comment has been minimized.

@hauntsaninja
Copy link
Collaborator

from functools import partial
def foo(): ...
partial(partial, foo)()

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: 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: note: "partial[object | Coroutine[None, None, object | None] | None].__call__" has type "Callable[[VarArg(Any), KwArg(Any)], object | Coroutine[None, None, object | None] | None]"

ibis (https://github.com/ibis-project/ibis)
+ ibis/backends/sql/datatypes.py: error: "int" not callable  [operator]
+ ibis/backends/sql/datatypes.py:31: error: Too many arguments for "__call__"  [call-arg]
+ ibis/backends/sql/datatypes.py:48: error: Too many arguments for "__call__"  [call-arg]

@hauntsaninja hauntsaninja merged commit 1b116df into python:master Jun 23, 2024
18 checks passed
@ilevkivskyi ilevkivskyi deleted the partial-explicit branch June 23, 2024 09:11
@cdce8p
Copy link
Collaborator

cdce8p commented Jun 23, 2024

This PR seems to cause a false-positive with partial and not callable.

from functools import partial

class A:
    def __init__(self, var: str, b: int, c: int) -> None: ...

partial(A, str(1))  # false-positive
reveal_type(1)
test.py: error: "str" not callable  [operator]

Note: The error doesn't include a line number which made it difficult to default. Additionally, the __init__ signature seems to need three variables for the error to be emitted.

Furthermore, it isn't limited to str(...).

from functools import partial
class B: ...

class C:
    def __init__(self, var: B, b: int, c: int) -> None: ...

partial(C, B())  # false_positive
test.py: error: "B" not callable  [operator]

@ilevkivskyi
Copy link
Member Author

Yes, this is a bug, fix in #17429

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression on validation of manual type annotations to functools.partial between stable version and git
3 participants