python / python/mypy

Inconsistency for `[func-returns-value]`: Error not reported for `staticmethod`s

Open
#14,179 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Bug Report

Static methods decorated with staticmethod that return None do not result in a [func-returns-value] error being reported.

To Reproduce

https://mypy-play.net/?mypy=latest&python=3.11&gist=519f480fe4f8840e0043c2555f951f2f

class Example:
    def no_op0(self) -> None:
        return None
        
    @staticmethod
    def no_op0s() -> None:
        return None
        
    def no_op1(self) -> None:
        return
    
    @staticmethod    
    def no_op1s() -> None:
        return
    
ex = Example()

# error: "no_op0" of "Example" does not return a value  [func-returns-value]
assert ex.no_op0() is None

# Decorated version is fine
assert ex.no_op0s() is None

# error: "no_op1" of "Example" does not return a value  [func-returns-value]
assert ex.no_op1() is None

# Decorated version is fine
assert ex.no_op1s() is None

Expected Behavior

A static method is just another callable and it makes sense for the behavior of the [func-returns-value] error to be the same for it as for other callables.

Actual Behavior

The behavior of the [func-returns-value] error for decorated static methods is different from that for other callables. No error is reported.

Your Environment

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

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

Start with the linked mypy-play reproduction and trace the [func-returns-value] check for calls to static methods decorated with staticmethod. Done means static methods returning None produce the same error as equivalent undecorated methods, while the existing behavior for other callables remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.