Skip to content

staticmethod return type is not inferred correctly #8181

Closed
@lovasoa

Description

@lovasoa
  • Are you reporting a bug, or opening a feature request?
    reporting a bug
  • Please insert below the code you are checking with mypy,
    or a mock-up repro if the source is private. We would appreciate
    if you try to simplify your case to a minimal repro.
class A:
    @staticmethod
    def f(x: int) -> str: raise NotImplementedError

class B(A):
    f = staticmethod(chr)

assert B().f(97) == "a"
  • What is the actual behavior/output?
asd.py:6: error: Incompatible types in assignment (expression has type "staticmethod", base class "A" defined the type as "Callable[[int], str]")
asd.py:8: error: Cannot determine type of 'f'
  • What is the behavior/output you expect?
    I think this should not raise any type error.

  • What are the versions of mypy and Python you are using?
    mypy 0.720
    Python 3.7.5

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