KotlinIsland / KotlinIsland/basedmypy
decorator that takes a named `Callable` fails when function is decorated with `@staticmethod`
Open
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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