Skip to content

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

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.

Activity

  1. gnprice commented on Aug 1, 2016

    @gnprice
    CollaboratorAuthor

    This looks like it will probably be fixed by doing #1975. It'd be useful to debug a bit to confirm that.

  2. added this to the milestone on Aug 4, 2016
  3. ddfisher commented on Aug 4, 2016

    @ddfisher
    Collaborator

    Fixed by #1980.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions