Skip to content

Commit

Permalink
fix JsonObject class, set version to 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelliao committed Feb 13, 2014
1 parent 94c47f6 commit 9437b40
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Version 1.0.0 released 2013-06-24

* Initial release.

Version 1.1.0 released 2014-02-13

* Add py3 support;
* Add x_ratelimit_reset;
* Fix JsonObject class.
15 changes: 6 additions & 9 deletions github.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def bytes(string, encoding=None):

TIMEOUT=60

__version__ = '1.0.0'
__version__ = '1.1.0'

_URL = 'https://api.github.com'
_METHOD_MAP = dict(
Expand Down Expand Up @@ -293,18 +293,15 @@ class JsonObject(dict):
'''
general json object that can bind any fields but also act as a dict.
'''
def __getattr__(self, attr):
return self[attr]
def __getattr__(self, key):
try:
return self[key]
except KeyError:
raise AttributeError(r"'Dict' object has no attribute '%s'" % key)

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

def __getstate__(self):

This comment has been minimized.

Copy link
@candeira

candeira Feb 28, 2014

Contributor

I'm curious to know why did you remove these two methods?

This comment has been minimized.

Copy link
@michaelliao

michaelliao Mar 1, 2014

Author Owner

I found if an AttributeError raised instead of KeyError, the behavior is the same as a normal object, and getstate, setstate are no longer needed. code:

x = obj[key] # KeyError!
x = obj.key # AttributeError!

return self.copy()

def __setstate__(self, state):
self.update(state)

if __name__ == '__main__':
import doctest
doctest.testmod()

0 comments on commit 9437b40

Please sign in to comment.