Re: [Python-Dev] python and super

2011-04-14 Thread Terrence Cole
On Thu, 2011-04-14 at 17:10 +0100, Michael Foord wrote:
> On 14/04/2011 17:02, Raymond Hettinger wrote:
> > On Apr 14, 2011, at 8:34 AM, P.J. Eby wrote:
> >
> >> At 03:55 PM 4/14/2011 +0100, Michael Foord wrote:
> >>> Ricardo isn't suggesting that Python should always call super for you, 
> >>> but when you *start* the chain by calling super then Python could ensure 
> >>> that all the methods are called for you. If an individual method doesn't 
> >>> call super then a theoretical implementation could skip the parents
> >>> methods (unless another child calls super).
> >> That would break classes that deliberately don't call super.  I can think 
> >> of examples in my own code that would break, especially in __init__() 
> >> cases.
> >>
> >> It's perfectly sensible and useful for there to be classes that 
> >> intentionally fail to call super(), and yet have a subclass that wants to 
> >> use super().  So, this change would expose an internal implementation 
> >> detail of a class to its subclasses, and make "fragile base class" 
> >> problems worse.  (i.e., where an internal change to a base class breaks a 
> >> previously-working subclass).
> > I agree.  Better for someone to submit a recipe for a variant of super and 
> > see if there is any uptake.
> 
> In Python 3 super is treated specially by the compiler, so an 
> alternative implementation that behaves similarly to the built-in one 
> modulo this change is not possible.

I know that super does some astonishing *runtime* hackery with co_code
when you don't pass arguments, but I thought that was all that was
needed.  What does the compiler have to do specially for super that
would prevent somebody from implementing something like it?

> Two use cases for the suggested alternative behaviour have been 
> presented. What is the use case for a method not wanting to prevent its 
> *sibling* methods in a multiple inheritance situation being called?
> 
> I believe the use case Phillip (and others) have presented is for 
> methods preventing their *parent* methods being called.
>
> All the best,
> 
> Michael Foord
> 
> >
> > Raymond
> >
> 
> 


___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Callable, non-descriptor class attributes.

2011-03-12 Thread Terrence Cole
On Sat, 2011-03-12 at 12:49 +1300, Greg Ewing wrote:
> Thomas Wouters wrote:
> 
> >  2. Make CFunctions turn into methods in CPython (after a period of 
> > warning about the impending change, obviously.) The actual *usecase* for 
> > this is hard to envision
> 
> While not necessary for the case being discussed here, this would
> be a big help for Pyrex and Cython, where currently some awkward
> things have to be done to get a Python class with methods implemented
> in C.

Just so.  I implemented a new C-level function type for Melano[1] just 2
days ago so that I can have the descriptor slot set (and get
__defaults__, __kw_defaults__, __annotations__, and any other missing
details from PyFunction that I want or need).

[1] https://github.com/terrence2/melano

___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Proposed tweaks to functools.wraps

2010-08-11 Thread Terrence Cole
On Wed, 2010-08-11 at 13:10 +1000, Nick Coghlan wrote:
> On Wed, Aug 11, 2010 at 12:39 PM, Benjamin Peterson  
> wrote:
> > which would require ignoring the absence of __annotations__.
> 
> It turns out the patch that added __annotations__ support also made a
> change to make all of the copied attributes optional.

The discussion happened on issue 8814.  I initially made only
__annotations__ optional, however, after finding issue 1576241 on the
tracker and thinking about it a bit, making all of the annotations
optional seemed like the only sane solution.

http://bugs.python.org/issue8814
http://bugs.python.org/issue1576241

> So I'll be tidying up the implementation of that, extending it to the
> updated attributes and adding unit tests to make sure they're all
> optional.
> 
> Cheers,
> Nick.
> 
--
Terrence

___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com