KotlinIsland / KotlinIsland/basedmypy

decorator that takes a named `Callable` fails when function is decorated with `@staticmethod`

Open
#759 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
202
Forks
6
PR merge metrics
No merged PRs in 30d

Description

from __future__ import annotations

from types import FunctionType
from typing import Callable, Protocol


class Named(Protocol):
    __name__: str
    __qualname__: str


class Foo:
    @staticmethod
    def foo(fn: Callable[[str], None] & Named) -> FunctionType[[], None]:
        def wrapped():
            pass

        return wrapped

    @staticmethod
    @foo
    def bar(letter: str): ...


Foo().bar() # works at runtime
main.py: note: In class "Foo":
main.py:20:6: error: Argument 1 to "foo" of "Foo" has incompatible type "(letter: str) -> None"; expected "(str) -> None & Named"  [arg-type]
        @staticmethod
         ^
Found 1 error in 1 file (checked 1 source file)

https://mypy-play.net/?mypy=basedmypy-latest&python=3.12&gist=785d3f5c4dad6bd6a71c4c8520d10655

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the example in main.py using the linked mypy-play configuration, then trace how the decorator and staticmethod are checked. Done means the shown decorator usage type-checks without the arg-type error while preserving the stated runtime behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.