Skip to content

x in y doesn't report errors when x is not str and y: union | involving | str #21595

@bzoracler

Description

@bzoracler

Bug Report

This doesn't report an error but can easily crash at runtime:

var: list[int] | str
2 in var

Expected Behavior

var: list[int] | str
2 in var  # E: Unsupported operand types for in ("int" and "str") \
          # N: Right operand is of type "list[int] | str"

Your Environment

  • Mypy version used: 1.0.0-2.1.0
  • Mypy command-line flags: --strict

Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions