Skip to content

--strict-equality flag not working with membership operator and Literal types #17062

Open
@mflova

Description

@mflova

Bug Report

When using any container (set, frozenset, list, tuples...) containing Literal based types, the --strict-equality is not detecting any issues when I use the membership operator in a non-overlapping check.

To Reproduce

from typing import Literal

OPTIONS = Literal["a", "b"]
var: list[OPTIONS] = ["a"]
if "c" in var:  # MYPY OK
    pass

Expected Behavior

When the flag --strict-equality is set, I would expect that mypy raises an erorr here. Same as it does when I do a non-overlapping equality check:

from typing import Literal

OPTIONS = Literal["a", "b"]
var: list[OPTIONS] = ["a"]
if var[0] == "c":  #  error: Non-overlapping equality check (left operand type: "Literal['a', 'b']", right operand type: "Literal['c']")  [comparison-overlap]
    pass

Actual Behavior

No errors are raised

Your Environment
Using Mypy version 1.9.0

Activity

changed the title [-]Strict equality flag not working with container filled with `Literal` types[/-] [+]`--strict-equality` flag not working with membership operator and `Literal` types[/+] on Mar 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @AlexWaygood@mflova

        Issue actions

          `--strict-equality` flag not working with membership operator and `Literal` types · Issue #17062 · python/mypy