python / python/cpython

New LOAD_ATTR_CLASS_WITH_METACLASS_CHECK does not guard against __class__ reassignment

Open
#149,239 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

interpreter-core type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

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
  • gh-149269

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

Start by running the issue's reproducer with and without interpreter specialization, focusing on LOAD_ATTR_CLASS_WITH_METACLASS_CHECK and the class reassignment. Compare the behavior against linked PR gh-149269; done means the specialized and unspecialized runs both return the descriptor result after reassignment.

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
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.