Skip to content

dis.dis has incorrect annotation #2914

Closed
@Hanaasagi

Description

@Hanaasagi

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions