10000 Cannot assert a callable returns `None` when it must return `None` · Issue #17568 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
cjw296 opened this issue Jul 23, 2024 · 1 comment
Open

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

cjw296 opened this issue Jul 23, 2024 · 1 comment
Labels
bug mypy got something wrong

Comments

@cjw296
Copy link
cjw296 commented Jul 23, 2024

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
@cjw296 cjw296 added the bug mypy got something wrong label Jul 23, 2024
@gandhis1
Copy link

The error is to prevent people from attempting to do things with the return values of functions that return None. Whether or not that thing is an assertion doesn't really seem relevant. As the point of Mypy is to statically verify things, supporting constructs used with dynamic type verification seem to be outside of the scope of Mypy. You can type: ignore[func-returns-value] if you need to.

At a minimum I'd argue this is a feature request, not a bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants
0