Skip to content

dis.dis has incorrect annotation #2914

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

Closed
Hanaasagi opened this issue Apr 12, 2019 · 1 comment · Fixed by #2969
Closed

dis.dis has incorrect annotation #2914

Hanaasagi opened this issue Apr 12, 2019 · 1 comment · Fixed by #2969

Comments

@Hanaasagi
Copy link
Contributor

Env

  • Python 3.7.2
  • MyPy 0.700

Problem Details

Following code

import dis


def f(a: int) -> int:
    return a + 2


dis.dis(f)

MyPy will report

x.py:8: error: Argument 1 to "dis" has incompatible type "Callable[[int], int]"; expected "Union[MethodType, FunctionType, CodeType, type, str, bytes]"

It seems MyPy does not parse it as types.FunctionType, I'm not sure it's a bug of MyPy or typeshed. I check the code of dis.dis (https://github.com/python/cpython/blob/9a3ffc0492d1310ead9ce8f5ee678c26b20a338d/Lib/dis.py#L34-L77), I think implementing a Protocol is a workaround.

@JelleZijlstra
Copy link
Member

This is arguably a mypy bug: mypy doesn't recognize that f is a FunctionType (python/mypy#3171). However, that's not easily fixable. A good workaround would be to make dis.dis accept Callable[..., Any].

JelleZijlstra added a commit to JelleZijlstra/typeshed that referenced this issue May 7, 2019
srittau pushed a commit that referenced this issue May 7, 2019
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 a pull request may close this issue.

2 participants