Commit d8e16b76 authored by Damian Johnson's avatar Damian Johnson
Browse files

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
parent 98d97717
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -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: