Skip to content

Return an instance of the property subclass from getter, setter and deleter - #1345

Open
taxor03 wants to merge 1 commit into
oracle:masterfrom
taxor03:GH-property-subclass-copy
Open

taxor03 wants to merge 1 commit into
oracle:masterfrom
taxor03:GH-property-subclass-copy

Conversation

@taxor03

@taxor03 taxor03 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #1341

PropertyCopyingNode.copy() built a plain property directly whenever IsBuiltinClassProfile matched PProperty. That profile also matches subclasses, so .getter(), .setter() and .deleter() of a property subclass returned a property, and @attr.setter dropped the subclass. CPython's property_copy always calls type(old) and sets the name only if the result is a property (descrobject.c#L1787-L1795).

AS-IS

>>> class CustomProperty(property): pass
>>> type(CustomProperty(None).setter(None))
<class 'property'>

TO-BE

<class '__main__.CustomProperty'>

(matching CPython)

Changes

  • In PropertyBuiltins.PropertyCopyingNode.copy(), take the shortcut only for exactly property (IsBuiltinClassExactProfile), and set the property name on the result of calling the subclass only if it is a PProperty, as CPython's PyObject_TypeCheck does, instead of casting.
  • Add test_property_subclass_copy to tests/test_property.py: a subclass used with @attr.setter and @attr.deleter keeps its type, and getting, setting and deleting still work. It passes on CPython 3.12, 3.13 and 3.14.

Testing

mx python-jvm on darwin-aarch64, then mx graalpytest test_property (6 passed) and --tagged test_property (23 passed). Without the change, the new test fails at type(p) is CustomProperty. mx checkstyle --primary and mx eclipseformat --primary report nothing.

…nd `deleter`

Signed-off-by: Sungmin Park <ryan040@korea.ac.kr>
@oracle-contributor-agreement oracle-contributor-agreement Bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Nov 24, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: getter, setter and deleter of a property subclass return a plain property, so @attr.setter drops the subclass

1 participant