KEMBAR78
Value incorrectly flagged as being possibly None after `or` predicate ensures it isn't None · Issue #3508 · python/mypy · GitHub
Skip to content

Value incorrectly flagged as being possibly None after or predicate ensures it isn't None #3508

@rowillia

Description

@rowillia

Invoked with: python3.6 -m mypy --warn-no-return --strict-optional test_or_shortcut.py

from typing import Optional, Any


def test_or_shortcut(value: Optional[Any]) -> None:
    if not value:
        pass
    if not value or value.get('foo') == 'hello':
        pass

Fails with:

test_or_shortcut.py:7: error: Item "None" of "Optional[Any]" has no attribute "get"

Oddly if I remove the first branch things typecheck fine:

from typing import Optional, Any


def test_or_shortcut(value: Optional[Any]) -> None:
    if not value or value.get('foo') == 'hello':
        pass

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions