Skip to content

Type inference regression with "and" and strict optional disabled #11705

Description

@JukkaL

This generates a false positive:

# mypy: no-strict-optionalfromtypingimportTuple, Dict, Optional, NamedTupleclassC(NamedTuple):
x: intt: Optional[C]
d: Dict[C, bytes]
x=tandd[t]
ifx:
x.startswith(b'x') # Item "C" of "Union[C, bytes]" has no attribute "startswith"

It started happening as a side effect of #10389.

This is a regression, so this may be high priority. However, since this only seems to happen when strict optional checking is disabled, the impact may be pretty minor.

cc @ethan-leba

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongfalse-positivemypy gave an error on correct code

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions