From af81088fb08525e617b8f1fad7deeabc47588c10 Mon Sep 17 00:00:00 2001 From: Lorenz Diener Date: Thu, 14 Dec 2017 13:16:28 +0100 Subject: Make attribute-style access better --- mastodon/Mastodon.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'mastodon') diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 722c4d5..13c3e38 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -1400,8 +1400,15 @@ class Mastodon: """ class AttribAccessDict(dict): def __getattr__(self, attr): - return self[attr] - + if attr in self: + return self[attr] + else: + raise AttributeError() + + def __setattr__(self, attr, val): + if attr in self: + raise AttributeError("Attribute-style access is read only") + super().__setattr__(attr, val) if isinstance(json_object, dict): return AttribAccessDict(json_object) return json_object -- cgit v1.2.3