Skip to content

Spurious error on Callables returning None, under strict-optional #1957

@gnprice

Description

@gnprice

Under --strict-optional, something goes wrong in handling Callable types with return type None so that we don't allow them to be used even where the very same type is expected.

Short repro:

$ cat /tmp/foo.py
from typing import Callable

def f() -> None:
  ...

x = f  # type: Callable[[], None]

$ mypy /tmp/foo.py --strict-optional
/tmp/foo.py:6: error: Incompatible types in assignment (expression has type Callable[[], None], variable has type Callable[[], None])

This is perfectly well-typed code, and we shouldn't be giving an error. Running mypy --strict-optional on mypy itself, there are 16 error messages that appear to be caused by this issue.

The error message itself also has the problem that it's complaining of incompatible types and then printing precisely the same type description twice. This may indicate a second independent bug; that'll become clearer with a diagnosis of this one.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions