Re: [Python-Dev] Multiple inheritance from builtin (C) types [still] supported in Python3?

2014-04-30 Thread Greg Ewing
Paul Sokolovsky wrote: Well, here it itches to ask if C++-like offsetting of subclass to base class this pointer was considered, I suppose in theory it would be possible to build a new set of __slot__ descriptors for the subclass. It mightn't even be all that difficult. My guess would be that

Re: [Python-Dev] Multiple inheritance from builtin (C) types [still] supported in Python3?

2014-04-30 Thread Guido van Rossum
It would be a disaster if the base class's slot descriptors would be broken by that though, so the implementation of slot descriptors would have to become more complicated. (It's worth understanding how __slots__ works. the interpreter first finds the slot on the class and then calls its __get__

Re: [Python-Dev] Multiple inheritance from builtin (C) types [still] supported in Python3?

2014-04-29 Thread PJ Eby
On Mon, Apr 28, 2014 at 7:26 PM, Paul Sokolovsky pmis...@gmail.com wrote: Well, sure I did, as I mentioned, but as that's first time I see that code (that specific piece is in typeobject.c:extra_ivars()), it would take quite some time be sure I understand all aspects of it. Thanks for

Re: [Python-Dev] Multiple inheritance from builtin (C) types [still] supported in Python3?

2014-04-29 Thread Guido van Rossum
Thanks -- your memory is better than mine! On Apr 29, 2014 8:16 AM, PJ Eby p...@telecommunity.com wrote: On Mon, Apr 28, 2014 at 7:26 PM, Paul Sokolovsky pmis...@gmail.comwrote: Well, sure I did, as I mentioned, but as that's first time I see that code (that specific piece is in

Re: [Python-Dev] Multiple inheritance from builtin (C) types [still] supported in Python3?

2014-04-29 Thread Paul Sokolovsky
Hello, On Tue, 29 Apr 2014 10:47:26 -0400 PJ Eby p...@telecommunity.com wrote: [] From memory of the last time I dealt with this, the rules were that you could mix two classes only if their __slots__ differed from their common __base__ by *at most* __dict__ and/or __weakref__. The dict

Re: [Python-Dev] Multiple inheritance from builtin (C) types [still] supported in Python3?

2014-04-29 Thread Guido van Rossum
When I redesigned and reimplemented this part of Python inheritance (somewhere in the 2.1 - 2.3 time frame, I forget the exact timing) I was well aware of the C++ approach and decided against it, preferring an approach requiring less compiler assistance that was easier for C programmers to use and

Re: [Python-Dev] Multiple inheritance from builtin (C) types [still] supported in Python3?

2014-04-29 Thread Nick Coghlan
On 29 April 2014 21:38, Guido van Rossum gu...@python.org wrote: When I redesigned and reimplemented this part of Python inheritance (somewhere in the 2.1 - 2.3 time frame, I forget the exact timing) I was well aware of the C++ approach and decided against it, preferring an approach requiring

[Python-Dev] Multiple inheritance from builtin (C) types [still] supported in Python3?

2014-04-28 Thread Paul Sokolovsky
Hello, It's more or less known fact (ref: google) that you can't inherit from multiple generic builtin (as in coded in C) types: class C(dict, list): pass TypeError: multiple bases have instance lay-out conflict However, more detailed googling led me to this page of a book:

Re: [Python-Dev] Multiple inheritance from builtin (C) types [still] supported in Python3?

2014-04-28 Thread Antoine Pitrou
On Mon, 28 Apr 2014 20:45:48 +0300 Paul Sokolovsky pmis...@gmail.com wrote: So, is that it, or disjoint native types are supported as bases somehow? Also, would someone know if a class-subclass case happens for example in stdlib? Well, for instance this trivial example works: class C(list,

Re: [Python-Dev] Multiple inheritance from builtin (C) types [still] supported in Python3?

2014-04-28 Thread Guido van Rossum
Antoine's example works because list inherits from object. The more general rule compatible layout only allows the rarest of cases to work -- basically the two classes involved must have a common base class and one of the classes must not add any C-level fields to that base class's layout. I would

Re: [Python-Dev] Multiple inheritance from builtin (C) types [still] supported in Python3?

2014-04-28 Thread Paul Sokolovsky
Hello, On Mon, 28 Apr 2014 20:24:58 +0200 Antoine Pitrou solip...@pitrou.net wrote: On Mon, 28 Apr 2014 20:45:48 +0300 Paul Sokolovsky pmis...@gmail.com wrote: So, is that it, or disjoint native types are supported as bases somehow? Also, would someone know if a class-subclass case

Re: [Python-Dev] Multiple inheritance from builtin (C) types [still] supported in Python3?

2014-04-28 Thread Antoine Pitrou
Hi Paul, On Mon, 28 Apr 2014 21:42:02 +0300 Paul Sokolovsky pmis...@gmail.com wrote: Basically, if two classes have compatible layouts, you can inherit from both at once. How is compatible layout defined? Or layout for that matter at all? See Guido's answer. I don't think it's

Re: [Python-Dev] Multiple inheritance from builtin (C) types [still] supported in Python3?

2014-04-28 Thread Guido van Rossum
On Mon, Apr 28, 2014 at 11:42 AM, Paul Sokolovsky pmis...@gmail.com wrote: Well, it's easy to treat object class as a special-case, null class. But the implementation doesn't, at least not for the question you're asking. So, let's re-formulate questions above with where such native base

Re: [Python-Dev] Multiple inheritance from builtin (C) types [still] supported in Python3?

2014-04-28 Thread Guido van Rossum
On Mon, Apr 28, 2014 at 12:02 PM, Antoine Pitrou solip...@pitrou.netwrote: On Mon, 28 Apr 2014 21:42:02 +0300 Paul Sokolovsky pmis...@gmail.com wrote: Basically, if two classes have compatible layouts, you can inherit from both at once. How is compatible layout defined? Or layout

Re: [Python-Dev] Multiple inheritance from builtin (C) types [still] supported in Python3?

2014-04-28 Thread Paul Sokolovsky
Hello, On Mon, 28 Apr 2014 12:08:40 -0700 Guido van Rossum gu...@python.org wrote: [] How is compatible layout defined? Or layout for that matter at all? The layout is what the C struct defining the object looks like. These are typically defined in headers in the Include directory