Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   When to derive from object? (http://www.velocityreviews.com/forums/t701425-when-to-derive-from-object.html)

Igor Mikushkin 10-13-2009 02:45 PM

When to derive from object?
 
Hello all!

I'm a newbie to Python.
Could you please say me when it is better to derive from "object" and
when not?

Thanks,
Igor

Bruno Desthuilliers 10-13-2009 02:49 PM

Re: When to derive from object?
 
Igor Mikushkin a écrit :
> Hello all!
>
> I'm a newbie to Python.


Welcome onboard

> Could you please say me when it is better to derive from "object" and
> when not?


- When not : when using Python >= 3.0, or when already subclassing
another class.

- When : any other case !-)


Matimus 10-13-2009 03:02 PM

Re: When to derive from object?
 
On Oct 13, 7:45*am, Igor Mikushkin <igor.mikush...@gmail.com> wrote:
> Hello all!
>
> I'm a newbie to Python.
> Could you please say me when it is better to derive from "object" and
> when not?
>
> Thanks,
> Igor


The only reason to derive from 'object' is if there is some sort of
weird side effect of using new style classes. I _have_ run into some
interesting scenarios when creating com objects in python using the
win32com module. Other than that, I always use new style classes
(derived from object).

Here are some articles that point out the distinctions between old and
new style classes: http://python.org/doc/newstyle/

Matt

Matimus 10-13-2009 03:33 PM

Re: When to derive from object?
 
On Oct 13, 8:02*am, Matimus <mccre...@gmail.com> wrote:
> On Oct 13, 7:45*am, Igor Mikushkin <igor.mikush...@gmail.com> wrote:
>
> > Hello all!

>
> > I'm a newbie to Python.
> > Could you please say me when it is better to derive from "object" and
> > when not?

>
> > Thanks,
> > Igor

>
> The only reason to derive from 'object' is ...


erm... that should say "the only reason _not_ to derive from object"
oops.

Matt

Anson Mackeracher 10-13-2009 05:34 PM

Re: When to derive from object?
 
Can someone point me to some reason on why not to derive from Object
when using Python >= 3.0? I am a Python novice, I need some
background.

On Oct 13, 10:49*am, Bruno Desthuilliers <bruno.
42.desthuilli...@websiteburo.invalid> wrote:
> Igor Mikushkin a écrit :
>
> > Hello all!

>
> > I'm a newbie to Python.

>
> Welcome onboard
>
> > Could you please say me when it is better to derive from "object" and
> > when not?

>
> - When not : when using Python >= 3.0, or when already subclassing
> another class.
>
> - When : any other case !-)



Benjamin Kaplan 10-13-2009 05:44 PM

Re: When to derive from object?
 
On Tue, Oct 13, 2009 at 1:34 PM, Anson Mackeracher <amackera@gmail.com> wrote:
> Can someone point me to some reason on why not to derive from Object
> when using Python >= 3.0? I am a Python novice, I need some
> background.
>


It's redundant. Python 3 cleaned up a lot of the warts that appeared
in Python over the years. Old-style classes (classes that didn't
inherit from object) were one of them. Every class in Python 3 is
derived from object whether you specify it or not.

> On Oct 13, 10:49*am, Bruno Desthuilliers <bruno.
> 42.desthuilli...@websiteburo.invalid> wrote:
>> Igor Mikushkin a écrit :
>>
>> > Hello all!

>>
>> > I'm a newbie to Python.

>>
>> Welcome onboard
>>
>> > Could you please say me when it is better to derive from "object" and
>> > when not?

>>
>> - When not : when using Python >= 3.0, or when already subclassing
>> another class.
>>
>> - When : any other case !-)

>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


Paul Rudin 10-13-2009 06:08 PM

Re: When to derive from object?
 
Benjamin Kaplan <benjamin.kaplan@case.edu> writes:

>
> It's redundant. Python 3 cleaned up a lot of the warts that appeared
> in Python over the years. Old-style classes (classes that didn't
> inherit from object) were one of them. Every class in Python 3 is
> derived from object whether you specify it or not.


.... it could be argued that having two ways to specify the same thing
(derivation from object explictly or implicitly) is a wart in itself :/

Terry Reedy 10-13-2009 07:28 PM

Re: When to derive from object?
 
Paul Rudin wrote:
> Benjamin Kaplan <benjamin.kaplan@case.edu> writes:
>
>> It's redundant. Python 3 cleaned up a lot of the warts that appeared
>> in Python over the years. Old-style classes (classes that didn't
>> inherit from object) were one of them. Every class in Python 3 is
>> derived from object whether you specify it or not.

>
> ... it could be argued that having two ways to specify the same thing
> (derivation from object explictly or implicitly) is a wart in itself :/


Every function with default arguments can be called two or more ways.
Every function that returns None can be written two or more ways.
;-)


greg 10-14-2009 12:18 AM

Re: When to derive from object?
 
Terry Reedy wrote:

> Every function with default arguments can be called two or more ways.
> Every function that returns None can be written two or more ways.


And in general, anything of any sort with any kind of
default can be written in two ways. Somehow I doubt that
the ZoP was intended to discourage providing defaults!

--
Greg


All times are GMT. The time now is 09:12 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.