-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Value incorrectly flagged as being possibly None after or
predicate ensures it isn't None
#3508
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
Comments
Hm, that looks like a binder bug. But I can't repro it. Does it still fail this way in master? |
@gvanrossum Repro'd on HEAD: rwilliams at rwilliams-mbp114-2 in ~/src/oss/mypy (master●) (venv)
$ python3.6 -m mypy -V
mypy 0.520-dev-72168faf682722ff8ffa6876d3c2fb94a30d5012 |
Ah, I did'nt copy the flags you are passing. Sorry. Labeled as bug affecting strict-optional. |
This looks familiar to me -- I think this might be to do with |
I was wrong -- it's actually related to truthiness tracking. For some reason, after the |
What if there is something other than |
I was wondering that too. I tried replacing the |
Okay, I think I've tracked this down to the root cause of the problem: |
I have the same problem, but with Here is my class AllowRandom(EnumMeta):
def get_random_item(self) -> enum.Enum: # but i'm not sure
return choice(list(self))
class PrefixSign(enum.Enum, metaclass=AllowRandom):
POSITIVE = 'positive'
NEGATIVE = 'negative' and when i tried this: def prefix(sign: Optional[PrefixSign] = None) -> str:
prefixes = {
'negative': ['...'],
'positive': ['...'],
}
if sign is None:
sign = PrefixSign.get_random_item()
if sign in PrefixSign:
return self.random.choice(prefixes[sign.value])
else:
raise NonEnumerableError(PrefixSign) I got this:
How to deal with this? |
@lk-geimfari I think your particular case may be related to the fact that the method |
@ilevkivskyi Unfortunately, it's did not help. I have updated the code which i write, please look above. The problem that i don't know which subclass of Enum will be returned and when i try annotate
|
@lk-geimfari You can try self-types instead of just returning |
Invoked with:
python3.6 -m mypy --warn-no-return --strict-optional test_or_shortcut.py
Fails with:
Oddly if I remove the first branch things typecheck fine:
The text was updated successfully, but these errors were encountered: