Unsupported operand type for ~ ("auto")
Nobody has claimed this yet.
- 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:
- https://mypy-play.net/?mypy=1.14.1&python=3.13 (fails)
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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