Skip to content

False positives with --strict-optional turned off #2999

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
pkch opened this issue Mar 14, 2017 · 1 comment
Closed

False positives with --strict-optional turned off #2999

pkch opened this issue Mar 14, 2017 · 1 comment

Comments

@pkch
Copy link
Contributor

pkch commented Mar 14, 2017

This is a low-priority issue (or maybe should even be closed), just wanted to add it for the record in case others run into it.

When --strict-optional is turned off, mypy in some cases is unable to infer the correct type inside ... if None else ... type conditionals; this doesn't happen always, only if it's preceded with assert isinstance(x, (X, type(None))) when x was known to be of type Base, which is the base class of X:

from typing import *

class A:
    a = 1

class B(A):
    b = 2

def f(x: Union[A, None]) -> None:
    assert isinstance(x, (B, type(None)))
    y = x.b if x is not None else x  # fails type check if --strict-optional is off, passes otherwise

The fix would be messy (mypy correctly analyzes the if statement, the problem is that it ignores the isinstance because it thinks that the assertion always succeeds anyway due to some problem with None handling).

@AlexWaygood
Copy link
Member

I'm closing this issue:

  • I can't reproduce the error on 0.620+ (I've tried installing earlier versions locally, but wasn't easily able to).
  • --strict-optional has been the default for a while now, and I think the people enabling the old behaviour with --no-strict-optional are becoming rarer and rarer.
  • There's been no activity on the issue since its creation five years ago.
  • The issue was low-priority when it was first created five years ago, and is even lower priority now.

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

No branches or pull requests

3 participants