python / python/mypy

Unsupported operand type for ~ ("auto")

Open
#18,410 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-enum
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

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: https://github.com/python/typeshed/commit/3e29e05e4ae28c9c17e2ada8f6f088de40e6d692.

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the provided enum.Flag reproduction with mypy 1.14.1 and compare it with 1.13.0 using the linked playgrounds. Start by tracing enum.auto() and inversion handling, including the referenced typeshed change; done means the example produces no unsupported-operand error and a regression test covers it.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.