On Sep 16, 2011, at 11:42 AM, Łukasz Rekucki wrote:

On 16 September 2011 10:17, Roald de Vries <downa...@gmail.com> wrote:
On Sep 16, 2011, at 12:11 AM, Łukasz Rekucki wrote:
I would like to also comment on the new approach in that ticket.
Making a shallow copy of a class is *MAGIC* to me. It breaks the basic invariant "issubsclass(decorator(A), A) == True". This is important if
you're planing to use this as "B = decorator()(A)" (and you are,
'cause the whole point of not modifying the original class is to allow
safely doing this), as you quickly end up with weird alternate
hierarchies. So, please don't do that :)

I agree that in an ideal world we'd have a better solution. On the other hand, the cbv-decorator using inheritance just didn't work, and the one using shallow copies does (if you don't use B=decorator()(A), indeed).

The one that just alters the given class also works, has no magic and
has the same limitation - dont' do "B = decorator(A)".

To show that this is actually a Python-thing, an analogous non- decorator-example:

    >>> class A(Base):
    ...     def method(self, *args, **kwargs):
    ...         super(A, self).method(*args, **kwargs)
    ...
    ... B = A
    ... A = SomeOtherClass
    ...
    ... B.method()
    Traceback (most recent call last):
        ...
TypeError: unbound method method() must be called with A instance as first argument (got nothing instead)

So IMHO it's "pythonic" to leave responsibility to use the decorator in the right way to the programmer.

Cheers, Roald

--
You received this message because you are subscribed to the Google Groups "Django 
developers" group.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to