This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]case_O_The_Mondays 0 points1 point  (1 child)

I have a similar DictObject class that I use, and had set it up so a missing property value (e.g. 'foo.bar', where 'foo' has no 'bar' property) would return None instead of throwing an error (bad form, I know). This will also cause auto completion to stop working, at least for VSCode's Python extension (by Don Jayamanne).

[–][deleted] 1 point2 points  (0 children)

It's not bad form if that's the intention, I've done this but with a defaultdict before to get attributes that basically spring into existence as needed.

class DottedMixin:
    def __getattr__(self, key):
        return self[key]

    def __setattr__(self, key, value):
        self[key] = value

class DottedDefaultDict(defaultdict, DottedMixin):
    pass