Skip to content

store_attr: does not update instance variable #496

@thatgeeman

Description

@thatgeeman

Hi! Thanks for this wonderful library. Reporting a scenario where store_attr does not behave the way I want it to:

# case 1: works
class T:
    def __init__(self, a, b, c):
        store_attr() 
    def __repr__(self):
        return f'T({self.__stored_args__})'

# case 2: fails
class T_:
    def __init__(self, a, b, c):
        self.a = a - 1  # modify variable a
        store_attr()
    def __repr__(self):
        return f'T({self.__stored_args__})'
        
T(1, 2, 3), T_(1, 2, 3)
# (T({'a': 1, 'b': 2, 'c': 3}), T_({'a': 1, 'b': 2, 'c': 3}))

In the second case, I would've expected T_.a to store the updated attribute, but this is not the case. Is this not the intended use case (to store all attributes) or is it supposed to be used only to store the args passed to instantiate the class?
Cheers,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions