Skip to content

[mypyc] Reject calling a property through class object - #22155

Open
rheard wants to merge 1 commit into
python:masterfrom
rheard:issue-1212-followup
Open

rheard wants to merge 1 commit into
python:masterfrom
rheard:issue-1212-followup

Conversation

@rheard

@rheard rheard commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #22139, from this review comment.

mypy types C.prop as the property's getter, so it accepts C.prop(obj). At runtime, C.prop is the property object (a getset descriptor for a native class), and calling it raises TypeError: 'property' object is not callable. For a native class, mypyc compiled C.prop(obj) as a direct call to the getter, so it returned obj.prop instead of raising. The same happened with inherited, read-write and trait properties, and with cls.prop(obj) in a classmethod of a class with no subclasses. If the getter was an abstract trait property with an empty body, the process aborted (Fatal Python error: Aborted).

mypyc now reports an error for these calls, like the existing error for accessing an instance attribute through a class object:

error: Cannot call property "prop" through class object

#18969 would make mypy report these calls ("property" not callable) in code that it type checks, but mypyc still needs its own check.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant