Skip to content

Commit

Permalink
LazyInstance: Work around issue #21
Browse files Browse the repository at this point in the history
I think this is a bug in (Ubuntu’s) Python v3.5: In the class LazyInstance,
_instance is a (known) @Property. Known attributes are not supposed to be
accessed via the __getattr__ special method. Nonetheless, the attribute
(property) access to self._instance triggers a call to
self.__getattr__('_instance'). Weird. Even weirder that this only happens from
within the ZIP code archive.

I worked around the issue with a regular instance method instead of a property.
  • Loading branch information
davidfoerster committed Oct 27, 2019
1 parent 7c1f9c8 commit ba3d24d
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/aptsources_cleanup/util/functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ def __init__(self, factory, type_hint=None, strict=False):
__hash__ = None


@property
def _instance(self):
def _get_instance(self):
"""Accesses the wrapped instance
and create it using the factory method provided earlier if necessary.
Expand All @@ -110,7 +109,7 @@ def __getattr__(self, name):
if callable(value):
return self._li_bind_method_impl(name)

return getattr(self._instance, name)
return getattr(self._get_instance(), name)


def _bind_method(self, *methods_or_names):
Expand Down Expand Up @@ -139,4 +138,4 @@ def _li_bind_method_impl(self, method_or_name):
return getattr(self._li_instance, method_or_name)
getter = attrgetter(method_or_name)

return lambda *args: getter(self._instance)(*args)
return lambda *args: getter(self._get_instance())(*args)

0 comments on commit ba3d24d

Please sign in to comment.