Skip to content

[Bug?] Inability to recognize None type has been removed from collection #8279

Closed

Description

@memery-rbx

Potential bug. One of my colleagues noticed that a collection of type Collection[Optional[float]] will act as if it is Collection[Optional[float]] even after any possible None is removed.

Minimal Example:

def mypy_subtract(nulled: bool) -> float:
    if nulled:
        returnable = [None, None]
    else:
        returnable = [1.0, 2.0]

    if None in returnable:
        raise Exception

    return returnable[0] - returnable[1]

What is the actual behavior/output?

itemscoringmigration/mypy_example.py:5: error: List item 0 has incompatible type "float"; expected "None"
itemscoringmigration/mypy_example.py:5: error: List item 1 has incompatible type "float"; expected "None"
itemscoringmigration/mypy_example.py:10: error: Unsupported left operand type for - ("None")

What is the behavior/output you expect?

No errors.

What are the versions of mypy and Python you are using?

mypy 0.761
Python 3.6.8

Do you see the same issue after installing mypy from Git master?

Yes.

No flags used.

Thanks for all the hard work. I love this package.

Activity

  1. JukkaL commented on Jan 15, 2020

    @JukkaL
    Collaborator

    Closing as duplicate of #2980. This is a relatively low-priority feature since this comes up pretty rarely and the implementation would be non-trivial (and there are some potential type safety issues).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions