GetAttr and failing to delegate setting of the attribute to the component

Hi there,

I am going through the fastcore and noticed that GetAttr is behaving a bit confusing:

class Author:
    def __init__(self, name): self.name = name

class ProductPage(GetAttr):
    _default = 'author'
    def __init__(self,author,price,cost): self.author,self.price,self.cost = author,price,cost

p = ProductPage(Author("Jeremy"), 1.50, 0.50)
[o for o in dir(p) if not o.startswith('_')]

returns

['author', 'cost', 'name', 'price']

now if I try to set that name attribute, that the p object has:

p.name = 'Michal'

I get name property on both objects:


print(p.author.name)
print(p.name)

[o for o in dir(p) if not o.startswith('_')]
Jeremy
Michal
['author', 'cost', 'name', 'name', 'price']

In my view it should either set the attribute of the component object properly, or forbid to set the attribute of the outer object? What do you think?
Best,

Michal

1 Like