Skip to content

AttributeError propagation is broken in cached_property with slots=True  #1230

@n-splv

Description

@n-splv

Let's start with a regular class:

class A:

    @cached_property
    def x(self):
        return self.y

    @property
    def y(self):
        raise AttributeError("Message")
        
a = A()
print(a.x)  # AttributeError: Message

Just as expected. Now let's use attrs with __dict__:

@define(slots=False)
class A:
    ...

print(a.x)  # AttributeError: Message

So far so good. But:

@define  # slots=True by default
class A:
    ...

print(a.x)  # AttributeError: 'A' object has no attribute 'y'

This made me spend quite some time wondering where did my attribute go :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions