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

Mypy 1.11.0 complains about Task typing #14756

Open
williamjamir opened this issue Jul 25, 2024 · 5 comments
Open

Mypy 1.11.0 complains about Task typing #14756

williamjamir opened this issue Jul 25, 2024 · 5 comments
Assignees
Labels
bug Something isn't working upstream dependency An upstream issue caused by a bug in one of our dependencies

Comments

@williamjamir
Copy link
Contributor

williamjamir commented Jul 25, 2024

Bug summary

Something has changed from mypy 1.10.1 to 1.11.0 that altered the behavior related to Task typing.
Consider this snippet:

from functools import partial
from typing import reveal_type

from prefect import task


@task
def test(a: int, b: int) -> None: ...


partial(test, a=1)
reveal_type(test)

I got the following output on mypy 1.11.0

 mypy acme.py
acme.py:10: error: "Task[[int, int], None]" not callable  [misc]
acme.py:11: note: Revealed type is "prefect.tasks.Task[[a: builtins.int, b: builtins.int], None]"

But I got the following output on mypy 1.10.1

 mypy acme.py           
acme.py:11: note: Revealed type is "prefect.tasks.Task[[a: builtins.int, b: builtins.int], None]"
Success: no issues found in 1 source file

Version info (prefect version output)

Version:             2.16.9
API version:         0.8.4
Python version:      3.11.5
Git commit:          083def52
Built:               Thu, Apr 4, 2024 3:11 PM
OS/Arch:             darwin/arm64
Profile:             default
Server type:         server

Additional context

No response

@williamjamir williamjamir added the bug Something isn't working label Jul 25, 2024
@zzstoatzz
Copy link
Collaborator

thanks @williamjamir for the issue! will take a look at this

@zzstoatzz
Copy link
Collaborator

zzstoatzz commented Jul 26, 2024

hi @williamjamir

using this MRE

» cat repros/task_typing.py
from functools import partial
from typing import reveal_type

from prefect import task

@task
def test(a: int, b: int) -> None: ...

partial(test, a=1)
reveal_type(test)

and this version of mypy

» pip freeze | rg mypy
mypy==1.11.0
mypy-extensions==1.0.0

I am not yet able to reproduce this on 2.16.9, newest 2.x, or 3.x

specific version checks
## 2.16.9
» uv pip install prefect==2.16.9 --force-reinstall
...
» mypy repros/task_typing.py
repros/task_typing.py:12: note: Revealed type is "Any"
Success: no issues found in 1 source file

## newest 2.x
» uv pip install -U prefect
...
» mypy repros/task_typing.py
repros/task_typing.py:12: note: Revealed type is "Any"
Success: no issues found in 1 source file

## newest 3.x
» uv pip install -U prefect --pre
...
» mypy repros/task_typing.py
repros/task_typing.py:12: note: Revealed type is "Any"
Success: no issues found in 1 source file

is there anything you notice that I'm missing here?

@williamjamir
Copy link
Contributor Author

williamjamir commented Jul 26, 2024

Thanks for looking at this @zzstoatzz !

It's odd that mypy is not detecting the correct typing for you. The output of reveal_type is Any, which, in my understanding, disables the check that would be made on partial.

I would expected to see the reveal_type instead as Task, like in my initial message.

@zzstoatzz
Copy link
Collaborator

taking another look, I was able to reproduce in a completely fresh sandbox environment

(root) root@678e57987c9b:~# mypy /tmp/repros/14756.py
/tmp/repros/14756.py:11: error: "Task[[int, int], None]" not callable  [misc]
/tmp/repros/14756.py:12: note: Revealed type is "prefect.tasks.Task[[a: builtins.int, b: builtins.int], None]"
Found 1 error in 1 file (checked 1 source file)

will dig into this

@zzstoatzz
Copy link
Collaborator

zzstoatzz commented Jul 29, 2024

it appears that I wasn't able to reproduce before because I had follow_imports = skip set, once I turned that off I could reliably reproduce.

I don't yet understand what mypy is on about here, since we overload __call__ for several cases (perhaps incorrectly somehow) so it should be recognized as a callable thing. (edit, its because of partial)

perhaps this issue is related? python/mypy#5079 (edit, I dont think it is)


edit actually it appears this might be more relevant python/mypy#17585

as without the partial, we pass fine. I would say for the moment, I think this is an upstream issue with mypy (as described in the above linked issue).

@zzstoatzz zzstoatzz added the upstream dependency An upstream issue caused by a bug in one of our dependencies label Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working upstream dependency An upstream issue caused by a bug in one of our dependencies
Projects
None yet
Development

No branches or pull requests

3 participants