Skip to content

--strict-equality should work with literal types #6672

@ilevkivskyi

Description

@ilevkivskyi

This example should give an error with --strict-equality:

def returns_a_or_b() -> Literal['a', 'b']:
  ...

if returns_a_or_b() == 'c':  # This can never by True
    ...

this depends on the implementation of type narrowing by equality checks, see #5935. Basically, Literal[...].__eq__() should provide a literal context for its argument.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions