diff options
| author | Damian Johnson <atagar@torproject.org> | 2015-05-18 12:11:47 -0700 |
|---|---|---|
| committer | Damian Johnson <atagar@torproject.org> | 2015-05-18 12:11:47 -0700 |
| commit | d8e16b765610160260e7e90693ffb2db08bb7dc5 (patch) | |
| tree | 8598e36470ceb0122c62e59653dffbc94d5dbd05 | |
| parent | 98d97717486063bb53bb297fde1cb1e9e73d89ff (diff) | |
Fix unpickling for python3
Turns out we can't use hasattr() since that triggers __getattr__() as well
under python3 (but not python2). The note about this...
"... it must do this by comparing the strings, rather than using hasattr or
testing for an AttributeError."
https://users.cs.cf.ac.uk/J.P.Giddy/python/gotcha/getattr.html
| -rw-r--r-- | stem/descriptor/__init__.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/stem/descriptor/__init__.py b/stem/descriptor/__init__.py index 5b07bc40..e8b581ed 100644 --- a/stem/descriptor/__init__.py +++ b/stem/descriptor/__init__.py @@ -594,9 +594,15 @@ class Descriptor(object): return stem.util.str_tools._to_unicode(digest_hash.hexdigest().upper()) def __getattr__(self, name): + # Our constructor sets these, but when unpickling we might lack them. This + # check is needed to avoid an infinite loop in that case. + + if name in ('_lazy_loading', 'ATTRIBUTES'): + return super(Descriptor, self).__getattribute__(name) + # If attribute isn't already present we might be lazy loading it... - if hasattr(self, '_lazy_loading') and self._lazy_loading and name in self.ATTRIBUTES: + if self._lazy_loading and name in self.ATTRIBUTES: default, parsing_function = self.ATTRIBUTES[name] try: |
