Skip to content

New LOAD_ATTR_CLASS_WITH_METACLASS_CHECK does not guard against __class__ reassignment #149239

@Fidget-Spinner

Description

@Fidget-Spinner

Bug description:

This was found by Codex. Consider the following:

import enum
import _testinternalcapi

class ColorMeta(enum.EnumType):
    pass

class Color(enum.IntEnum, metaclass=ColorMeta):
    RED = 1

red = Color.RED

class Descriptor(enum.IntEnum):
    RED = 1

    def __get__(self, obj, owner):
        return "descr"

def get_enum_member():
    return Color.RED

for _ in range(_testinternalcapi.SPECIALIZATION_THRESHOLD):
    assert get_enum_member() == 1

red.__class__ = Descriptor

for _ in range(_testinternalcapi.SPECIALIZATION_THRESHOLD):
    assert get_enum_member() == "descr"

This passes without specializing interpreter, but fails with. @kumaraditya303

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions