Re: If a class Child inherits from Parent, how to implement Child.some_method if Parent.some_method() returns Parent instance ?

2009-10-30 Thread Bruno Desthuilliers
metal a écrit : The actual situation is I'm coding with a immuable set-like datatype XSet which supports XSet(['al']) XSet(['ah'] = XSet(['ax'] I assume it was '==', not '=' if I declare ax is consists of al and ah That means I can't explian it very well 'cause my english... Now I try to

Re: If a class Child inherits from Parent, how to implement Child.some_method if Parent.some_method() returns Parent instance ?

2009-10-30 Thread Bruno Desthuilliers
metal a écrit : Consider the following: (snip) class Parent: def some_method(self): return Parent(...) class Child: pass Child().some_method() returns a Parent instance. It actually raises an AttributeError. You forgot to make Child inherit from Parent.

Re: If a class Child inherits from Parent, how to implement Child.some_method if Parent.some_method() returns Parent instance ?

2009-10-30 Thread metal
On 10月30日, 上午8时03分, metal metal...@gmail.com wrote: The actual situation is I'm coding with a immuable set-like datatype XSet which supports XSet(['al']) XSet(['ah'] = XSet(['ax'] if I declare ax is consists of al and ah A typo, XSet(['al']) | XSet(['ah'] = XSet(['ax'] --

Re: If a class Child inherits from Parent, how to implement Child.some_method if Parent.some_method() returns Parent instance ?

2009-10-30 Thread metal
On 10月30日, 下午4时44分, Bruno Desthuilliers bruno. 42.desthuilli...@websiteburo.invalid wrote: metal a écrit : The actual situation is I'm coding with a immuable set-like datatype XSet which supports XSet(['al']) XSet(['ah'] = XSet(['ax'] I assume it was '==', not '=' if I declare ax is

Re: If a class Child inherits from Parent, how to implement Child.some_method if Parent.some_method() returns Parent instance ?

2009-10-30 Thread Bruno Desthuilliers
metal a écrit : On 10月30日, 下午4时44分, Bruno Desthuilliers bruno. 42.desthuilli...@websiteburo.invalid wrote: metal a écrit : (snip) def methods(cls): return [k for k, v in cls.__dict__.items() if callable(v)] All callables are not functions or methods... The inspect module might

If a class Child inherits from Parent, how to implement Child.some_method if Parent.some_method() returns Parent instance ?

2009-10-29 Thread metal
Consider the following: class Parent: def some_method(self): return Parent(...) class Child: def some_method(self): ... return Parent.some_method(self)

Re: If a class Child inherits from Parent, how to implement Child.some_method if Parent.some_method() returns Parent instance ?

2009-10-29 Thread Christian Heimes
metal wrote: But this style makes code full with ugly self.__class__ Any standard/pythonic way out there? You are already using one standard way to implement an alternative constructor. If you don't need any instance attributes you can use another way: class Egg(object): @classmethod

Re: If a class Child inherits from Parent, how to implement Child.some_method if Parent.some_method() returns Parent instance ?

2009-10-29 Thread Chris Rebert
On Thu, Oct 29, 2009 at 3:45 PM, metal metal...@gmail.com wrote: Consider the following: snip class Parent:        def some_method(self):                return Parent(...) class Child:        pass Child().some_method() returns a Parent instance.

Re: If a class Child inherits from Parent, how to implement Child.some_method if Parent.some_method() returns Parent instance ?

2009-10-29 Thread Rhodri James
On Thu, 29 Oct 2009 22:45:45 -, metal metal...@gmail.com wrote: Consider the following: [fixed to actually inherit...] class Parent: def some_method(self): return Parent(...) class Child(Parent): pass

Re: If a class Child inherits from Parent, how to implement Child.some_method if Parent.some_method() returns Parent instance ?

2009-10-29 Thread Dave Angel
metal wrote: Consider the following: class Parent: def some_method(self): return Parent(...) class Child: def some_method(self): ... return Parent.some_method(self)

Re: If a class Child inherits from Parent, how to implement Child.some_method if Parent.some_method() returns Parent instance ?

2009-10-29 Thread metal
The actual situation is I'm coding with a immuable set-like datatype XSet which supports XSet(['al']) XSet(['ah'] = XSet(['ax'] if I declare ax is consists of al and ah That means I can't explian it very well 'cause my english... Now I try to make some mess like this...I know it's not good to