mirror of
https://github.com/django/django.git
synced 2025-09-18 00:10:22 +00:00
Fixed non-standard introspection support in LazyObject.
LazyObject called a public method ``get_all_members`` on wrapped objects in order to allow introspection. This could easily cause name clashes with existing methods on wrapped objects, and so has been changed to use the standard methods. This could be slightly backwards-incompatible, in obscure cases, if the undocumented LazyObject has been used externally. git-svn-id: http://code.djangoproject.com/svn/django/trunk@11636 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
22be3d7612
commit
c6e8e5d9f0
4 changed files with 39 additions and 11 deletions
|
@ -266,9 +266,6 @@ class LazyObject(object):
|
|||
def __getattr__(self, name):
|
||||
if self._wrapped is None:
|
||||
self._setup()
|
||||
if name == "__members__":
|
||||
# Used to implement dir(obj)
|
||||
return self._wrapped.get_all_members()
|
||||
return getattr(self._wrapped, name)
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
|
@ -286,6 +283,13 @@ class LazyObject(object):
|
|||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
# introspection support:
|
||||
__members__ = property(lambda self: self.__dir__())
|
||||
|
||||
def __dir__(self):
|
||||
if self._wrapped is None:
|
||||
self._setup()
|
||||
return dir(self._wrapped)
|
||||
|
||||
class SimpleLazyObject(LazyObject):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue