In the file subclassing.py, should the following:

def make_contrib(superclass, func=None):
    """
    Returns a suitable contribute_to_class() method for the Field subclass.

    If 'func' is passed in, it is the existing contribute_to_class() method on
    the subclass and it is called before anything else. It is assumed in this
    case that the existing contribute_to_class() calls all the necessary
    superclass methods.
    """
    def contribute_to_class(self, cls, name):
        if func:
            func(self, cls, name)
        else:
            super(superclass, self).contribute_to_class(cls, name)
        setattr(cls, self.name, Creator(self))

    return contribute_to_class

instead be:

def make_contrib(superclass, func=None):
    """
    Returns a suitable contribute_to_class() method for the Field subclass.

    If 'func' is passed in, it is the existing contribute_to_class() method on
    the subclass and it is called before anything else. It is assumed in this
    case that the existing contribute_to_class() calls all the necessary
    superclass methods.
    """
    def contribute_to_class(self, cls, name):
        if func:
            func(self, cls, name)
        else:
            super(superclass, self).contribute_to_class(cls, name)
            setattr(cls, self.name, Creator(self))

    return contribute_to_class

Should the setattr() should be called only when there isn’t a 
contribute_to_class() method. 

I ask because in my own custom field, I have a  contribute_to_class() function 
as well:

    def contribute_to_class(self, cls, name):
        super(myCustomField, self).contribute_to_class(cls, name)
        setattr(cls, self.name, myCustomCreator(self))

But, because of the setattr() in the SubfieldBase metaclass, my own setattr() 
gets overwritten by the default set_attr().. I therefore can’t have my own 
field of the same name with my own custom Creator().

Is this expected behavior?

-bobby



-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/B459F14E-F899-4972-BB04-F9AA95326FD7%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to