pyrefly icon indicating copy to clipboard operation
pyrefly copied to clipboard

`super()` object should not allow attribute assignment

Open grievejia opened this issue 7 months ago • 1 comments

Describe the Bug

Minimal repro:

class A:
    a: int = 3

class B(A): pass
super(B, B()).a = 3

Expected: Cannot assign to attribute a on type <super: <class 'B'>, B> Actual: No error

Sandbox Link

https://pyrefly.org/sandbox/?code=MYGwhgzhAECCBcAoaLpntAlgOwC7QF5oBmRRUSGAIQApYBKDAB0sQgFcmBTAJxqoA00WvXoA6MIRJA

(Only applicable for extension issues) IDE Information

No response

grievejia avatar May 18 '25 14:05 grievejia

For comparison, mypy gives "invalid assignment target", and after lifting super(B, B()) into a variable it gives "super has no attribute a"

pyright is OK with that snippet

yangdanny97 avatar May 29 '25 18:05 yangdanny97

We probably want to make check_attr_set_and_infer_narrow and check_attr_delete fail for AttributeBase::SuperInstance. Should be a relatively small change.

Integration tests should be added in pyrefly/lib/test

yangdanny97 avatar Jun 17 '25 02:06 yangdanny97

Interested in working on this!

regexyl avatar Jul 17 '25 09:07 regexyl

Assigned, thanks!

yangdanny97 avatar Jul 17 '25 12:07 yangdanny97