On 15/01/2015 00:40, Steven D'Aprano wrote:
jason wrote:
class B(A):
def __init__(self, s):
A.__init__(self, s)
Unrelated:
It is better to call super than manually call the superclass. Calling A
directly means your class is no longer compatible with multiple
inheritance.
jason wrote:
> If I have a class hierarchy like so:
>
>
> class A(object):
> def __init__(self, s):
> self.s = s
> def foo(self, s):
> return A(s)
A.foo is broken, or at least rude. Change it to this:
def foo(self, s):
return type(self)(s)
>
On 01/14/2015 01:10 PM, jason wrote:
On Wednesday, January 14, 2015 at 12:05:55 PM UTC-5, Mark Lawrence wrote:
I'm confused, can you please explain what you're trying to achieve
rather than how you're trying to achieve it and I'm sure that others
will give better answers than I can :)
Good c
On Wed, 14 Jan 2015 17:05:27 +, Mark Lawrence wrote:
> On 14/01/2015 16:45, jason wrote:
>> If I have a class hierarchy like so:
>>
>>
>> class A(object):
>>def __init__(self, s):
>> self.s = s
>>def foo(self, s):
>> return A(s)
>>
>> class B(A):
>>
On Wednesday, January 14, 2015 at 12:05:55 PM UTC-5, Mark Lawrence wrote:
> I'm confused, can you please explain what you're trying to achieve
> rather than how you're trying to achieve it and I'm sure that others
> will give better answers than I can :)
>
Good call. Coming up with a minimal
On 14/01/2015 16:45, jason wrote:
If I have a class hierarchy like so:
class A(object):
def __init__(self, s):
self.s = s
def foo(self, s):
return A(s)
class B(A):
def __init__(self, s):
A.__init__(self, s)
If I make a B:
b = B(0)
On Thu, Jan 15, 2015 at 3:45 AM, jason wrote:
> If I have a class hierarchy like so:
>
>
> class A(object):
> def __init__(self, s):
> self.s = s
> def foo(self, s):
> return A(s)
>
> class B(A):
> def __init__(self, s):
> A.__init__(self, s)
>
On Wed, Jan 14, 2015 at 9:45 AM, jason wrote:
> class A(object):
> def __init__(self, s):
> self.s = s
> def foo(self, s):
> return A(s)
Instead of explicitly naming the return class here, do this:
return self.__class__(s)
Alternatively, since you never u
If I have a class hierarchy like so:
class A(object):
def __init__(self, s):
self.s = s
def foo(self, s):
return A(s)
class B(A):
def __init__(self, s):
A.__init__(self, s)
If I make a B:
b = B(0)
I'd like b.foo(1) to return an instance o