2009/3/29 Scott David Daniels <scott.dani...@acm.org>:
> mark.sea...@gmail.com wrote:
>>
>> On Mar 29, 9:52 pm, Chris Rebert <c...@rebertia.com> wrote:
>>>
>>> On Sun, Mar 29, 2009 at 9:18 PM,  <mark.sea...@gmail.com> wrote:
>>>>
>>>> ...
>>>
>>> ... Also, you shouldn't use `class_ ` as the name of the first argument
>>> to
>>> __new__(). Use `cls` instead since that's the conventional name for
>>> it.
>
> Actually, according to PEP 8, class_ is the preferred name.

In other contexts where you have a class as a variable, yes, but not
in the case of classmethods such as this. See the docs for __new__
itself for example
(http://docs.python.org/reference/datamodel.html#object.__new__).

>>> My best guess as to what you're trying to do is (completely untested):
>>> class myclass(long):
>>>    def __new__(cls, init_val, reg_info):
>>>        print reg_info.message
>>>        instance = long.__new__(cls, init_val)
>>>        instance.reg_info = reg_info
>>>        return instance
>
> Normally, these changes are done in the __init__ phase (post-instance
> creation), so you might go for something like:

I think the whole reason he's using __new__ instead of __init__ is
because of this tidbit from the aforementioned __new__() docs:
"""
__new__() is intended mainly to allow subclasses of immutable types
(like int, str, or tuple) to customize instance creation. It is also
commonly overridden in custom metaclasses in order to customize class
creation.
"""

Cheers,
Chris

-- 
I have a blog:
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to