Skip to content

Unsupported operand type for ~ ("auto") #18410

@edgarrmondragon

Description

@edgarrmondragon

Bug Report

Starting with mypy 1.14.0, we started getting an error for an enum class that defines a member as an inversion (i.e. ~) of a different member that is declared with enum.auto().

To Reproduce

import enum


class Example(enum.Flag):
    USER = enum.auto()
    ADMIN = enum.auto()
    MACHINE = enum.auto()

    HUMAN = ~MACHINE

Playground links:

  1. https://mypy-play.net/?mypy=1.14.1&python=3.13 (fails)
  2. https://mypy-play.net/?mypy=1.13.0&python=3.13 (succeeds)

Expected Behavior

The operator should be supported for enum.Flag "auto" members.

Actual Behavior

enum_typing_repro.py:9: error: Unsupported operand type for ~ ("auto")  [operator]
Found 1 error in 1 file (checked 1 source file)

FWIW I wonder if this is related to recent changes in typeshed: python/typeshed@3e29e05.

Your Environment

  • Mypy version used: 1.14.1
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.13

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions