Author: lukeplant
Date: 2009-10-19 16:48:06 -0500 (Mon, 19 Oct 2009)
New Revision: 11636
Added:
django/trunk/docs/releases/1.2-alpha.txt
Modified:
django/trunk/django/conf/__init__.py
django/trunk/django/core/files/storage.py
django/trunk/django/utils/functional.py
Log:
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.
Modified: django/trunk/django/conf/__init__.py
===================================================================
--- django/trunk/django/conf/__init__.py 2009-10-19 21:17:33 UTC (rev
11635)
+++ django/trunk/django/conf/__init__.py 2009-10-19 21:48:06 UTC (rev
11636)
@@ -108,9 +108,6 @@
os.environ['TZ'] = self.TIME_ZONE
time.tzset()
- def get_all_members(self):
- return dir(self)
-
class UserSettingsHolder(object):
"""
Holder for user configured settings.
@@ -129,8 +126,11 @@
def __getattr__(self, name):
return getattr(self.default_settings, name)
- def get_all_members(self):
+ def __dir__(self):
return dir(self) + dir(self.default_settings)
+ # For Python < 2.6:
+ __members__ = property(lambda self: self.__dir__())
+
settings = LazySettings()
Modified: django/trunk/django/core/files/storage.py
===================================================================
--- django/trunk/django/core/files/storage.py 2009-10-19 21:17:33 UTC (rev
11635)
+++ django/trunk/django/core/files/storage.py 2009-10-19 21:48:06 UTC (rev
11636)
@@ -118,10 +118,6 @@
"""
raise NotImplementedError()
- # Needed by django.utils.functional.LazyObject (via DefaultStorage).
- def get_all_members(self):
- return self.__members__
-
class FileSystemStorage(Storage):
"""
Standard filesystem storage
Modified: django/trunk/django/utils/functional.py
===================================================================
--- django/trunk/django/utils/functional.py 2009-10-19 21:17:33 UTC (rev
11635)
+++ django/trunk/django/utils/functional.py 2009-10-19 21:48:06 UTC (rev
11636)
@@ -266,9 +266,6 @@
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,7 +283,14 @@
"""
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):
"""
A lazy object initialised from any function.
Added: django/trunk/docs/releases/1.2-alpha.txt
===================================================================
--- django/trunk/docs/releases/1.2-alpha.txt (rev 0)
+++ django/trunk/docs/releases/1.2-alpha.txt 2009-10-19 21:48:06 UTC (rev
11636)
@@ -0,0 +1,28 @@
+
+Backwards-incompatible changes
+==============================
+
+LazyObject
+----------
+
+``LazyObject`` is an undocumented utility class used for lazily wrapping other
+objects of unknown type. In Django 1.1 and earlier, it handled introspection
in
+a non-standard way, depending on wrapped objects implementing a public method
+``get_all_members()``. Since this could easily lead to name clashes, it has
been
+changed to use the standard method, involving ``__members__`` and
``__dir__()``.
+If you used ``LazyObject`` in your own code, and implemented the
+``get_all_members()`` method for wrapped objects, you need to make the
following
+changes:
+
+ * If your class does not have special requirements for introspection (i.e. you
+ have not implemented ``__getattr__()`` or other methods that allow for
+ attributes not discoverable by normal mechanisms), you can simply remove the
+ ``get_all_members()`` method. The default implementation on ``LazyObject``
+ will do the right thing.
+
+ * If you have more complex requirements for introspection, first rename the
+ ``get_all_members()`` method to ``__dir__()``. This is the standard method,
+ from Python 2.6 onwards, for supporting introspection. If you are require
+ support for Python < 2.6, add the following code to the class::
+
+ __members__ = property(lambda self: self.__dir__())
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---