Skip to content

Conversation

@erikgaas
Copy link
Contributor

@erikgaas erikgaas commented Dec 4, 2025

Fixes #496

store_attr now checks if an attribute already exists on self before storing, preserving any modifications made before calling store_attr().

Before:

class T_:
    def __init__(self, a, b, c):
        self.a = a - 1
        store_attr()  # self.a gets overwritten back to original 'a'

After:

class T_:
    def __init__(self, a, b, c):
        self.a = a - 1
        store_attr()  # self.a stays as a - 1

The fix uses getattr(self, n, fr.f_locals[n]) to prefer existing attribute values over the original arguments.

@erikgaas erikgaas changed the base branch from master to main December 4, 2025 07:10
@erikgaas erikgaas requested a review from jph00 December 4, 2025 07:10
@erikgaas erikgaas added the enhancement New feature or request label Dec 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

store_attr: does not update instance variable

2 participants