Skip to content

Cannot assert a callable returns None when it must return None #17568

@cjw296

Description

@cjw296

Bug Report

mypy prevents you making assertions about callables that must return None when they're called.
This is important as not everyone works in a type-checked context, and so library code must be robust to this.
In my case, I have a chain of callables, the ones in the middle take iterables and return iterables, but the one at the start must take no arguments and the one at the end must consume the upstream iterable and return nothing.

To Reproduce

def returns_none() -> None:
    pass

assert returns_none() is None

Expected Behavior

No mypy complaints

Actual Behavior

"returns_none" does not return a value (it only ever returns None) [func-returns-value]

Your Environment

  • Mypy version used: mypy 1.10.1 (compiled: yes)
  • Mypy command-line flags: none
  • Python version used: Python 3.12.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions