Skip to content

mypy on python 3.9 does not support @staticmethod in Protocols #15257

Open
@graingert

Description

@graingert

Bug Report

(A clear and concise description of what the bug is.)

To Reproduce

from __future__ import annotations

from typing import Protocol

class Demo(Protocol):
    @staticmethod
    def demo(v: int) -> int:
        pass


def returns_one(v: int) -> int:
    return 1

class Inheriting(Demo):
    demo = staticmethod(returns_one)

https://mypy-play.net/?mypy=latest&python=3.9&gist=1438683686842d8a03bfbc32646c7952&flags=strict

Expected Behavior

Success: no issues found in 1 source file

Actual Behavior

main.py:15: error: Incompatible types in assignment (expression has type "staticmethod[[int], int]", base class "Demo" defined the type as "Callable[[int], int]") [assignment]

Your Environment

  • Mypy version used: 1.3.0
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.9

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-descriptorsProperties, class vs. instance attributes

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions