Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

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

Closed
memery-rbx opened this issue Jan 15, 2020 · 1 comment
Closed

Comments

@memery-rbx
Copy link

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.

@JukkaL
Copy link
Collaborator

JukkaL commented Jan 15, 2020

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).

@JukkaL JukkaL closed this as completed Jan 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants