Skip to content

Unnecessary specialization failures of LOAD_ATTR and STORE_ATTR when attributes are shadowed by the object's class. #123040

Closed
@markshannon

Description

@markshannon

This applies to both instances and classes.
If an object and it's class both have attributes with the same name, this prevents specialization of access to the object's attribute.
However, in this case specialization should only be prevented if the class's attribute is a data descriptor.

Example 1, instance:

class C:
    x = 1
    def __init__(self):
        self.x = 2

C().x

C().x above is 2. It doesn't matter that C.x exists, provided it isn't a data descriptor.
This failure shows up as "shadowed" in the stats

Example 2, class:

class Meta(type):
    x = 1
class C(metaclass=Meta):
    x = 1

C.x

C.x is 2. Meta.x doesn't change that, as it isn't a data descriptor.
This failure shows up as "metaclass attribute" in the stats

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14new features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usage

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions