Skip to content

Enum _missing_ function changes __contains__ behaviour #132684

Open
@artur-sl

Description

@artur-sl

Bug report

Bug description:

I observed different behavior for Enum __contains__ in 3.13.2 and 3.13.3 if there is _missing_ method implemented:

from enum import Enum

class Color(Enum):
    RED = 1
    
    @classmethod
    def _missing_(cls, value):
        return cls.RED

# 3.13.2
>>> "blue" in Color
False

# 3.13.3
>>> "blue" in Color
True

IMO _missing_ should only influence the __call__ method:

# both 3.13.2 and 3.13.3
>>> Color("blue")
<Color.RED: 1>

CPython versions tested on:

3.13

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixes3.13bugs and security fixes3.14new features, bugs and security fixesrelease-blockerstdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions