Complaint about @staticmethod outside a class

Open
#1,006 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
python
Domain
tooling

Research direction

The issue only supplies an inline Python example and the reported diagnostic; begin by reproducing it with mypy, then trace the diagnostic handling for staticmethod used inside a function. Done should be a decided behavior for this case, documented by a regression test if the project confirms it as a bug.

Written by the indexing model from the issue text.

Description

false-positive feature priority-2-low

I found code like this:

def foo():
    @staticmethod
    def bar():
        pass

This gets an error:

/Users/guido/mypy_tests/mypy_static.py: note: In function "foo":
/Users/guido/mypy_tests/mypy_static.py:2: error: 'staticmethod' used with a non-method

It can be silenced by putting # type: ignore on the @staticmethod line.

Dominant language
Python
Stars
20.6k
Forks
3.3k
Avg merge
1d 18h
Merged PRs (30d)
54

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.

More from python/mypy

All issues in python/mypy

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.