Skip to content

DADict use self __setitem__ instead of elements __setitem__#876

Merged
jhpyle merged 2 commits intojhpyle:masterfrom
jpagh:dadict-self-setitem
Jan 1, 2026
Merged

DADict use self __setitem__ instead of elements __setitem__#876
jhpyle merged 2 commits intojhpyle:masterfrom
jpagh:dadict-self-setitem

Conversation

@jpagh
Copy link
Contributor

@jpagh jpagh commented Nov 15, 2025

Since the default __setitem__() method in a DADict looks like this:

    def __setitem__(self, key, the_value):
        self.elements[key] = the_value

I wanted to update all of the methods in a DADict to use the class's self.__setitem__() via self[key] = notation instead of the elements's self.elements.__setitem__() via self.elements[key] = notation. This would allow me to be able to override only the __setitem__() method in my custom DADict class (which validates the key before assignment) rather than having to validate the key in a few different places which required additional method overrides.

The method new() already does this (self[parg] = None), but the method initializeObject() does not (self.elements[entry] = newobject).

@jpagh jpagh changed the title Dadict self setitem DADict use self __setitem__ instead of elements __setitem__ Nov 15, 2025
@jhpyle jhpyle merged commit 047f428 into jhpyle:master Jan 1, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants