-
Notifications
You must be signed in to change notification settings - Fork 297
Pyrefly doesn't support setting an instance attribute to a descriptor #1803
Copy link
Copy link
Closed
Labels
Description
Describe the Bug
If you set an instance attribute to a descriptor (rather than setting it at the class level), pyrefly should just treat it as as a regular instance attribute with no descriptor behavior. This works in pyright and (mostly) in mypy (mypy doesn't error but doesn't infer precise types). Pyrefly gets confused:
from typing import assert_type
class MyDescriptor:
def __get__(self, instance, owner=None):
return 42
class A:
def __init__(self):
self.a = MyDescriptor() # error: Attribute `a` of class `A` is a read-only descriptor
assert_type(A().a, MyDescriptor) # error: assert_type(Literal[42], MyDescriptor) failed
I saw this in real-world code using the torch.device class (which has a __get__ method but no __set__): https://github.com/search?q=repo%3Apytorch%2Fignite+%22self._device+%3D%22&type=code.
Sandbox Link
(Only applicable for extension issues) IDE Information
No response
Reactions are currently unavailable