Re: [Python-Dev] What is the design purpose of metaclasses vs code generating decorators? (was Re: PEP 557: Data Classes)

2017-10-20 Thread Ronald Oussoren
> On 14 Oct 2017, at 16:37, Martin Teichmann wrote: > >> Things that will not work if Enum does not have a metaclass: >> >> list(EnumClass) -> list of enum members >> dir(EnumClass) -> custom list of "interesting" items >> len(EnumClass) -> number of members >>

Re: [Python-Dev] What is the design purpose of metaclasses vs code generating decorators? (was Re: PEP 557: Data Classes)

2017-10-14 Thread Ivan Levkivskyi
On 14 October 2017 at 17:49, Ethan Furman wrote: > The problem with PEP 560 is that it doesn't allow the class definition > protections that a metaclass does. > Since the discussion turned to PEP 560, I can say that I don't want this to be a general mechanism, the PEP

Re: [Python-Dev] What is the design purpose of metaclasses vs code generating decorators? (was Re: PEP 557: Data Classes)

2017-10-14 Thread Ethan Furman
On 10/14/2017 07:37 AM, Martin Teichmann wrote: Things that will not work if Enum does not have a metaclass: list(EnumClass) -> list of enum members dir(EnumClass) -> custom list of "interesting" items len(EnumClass) -> number of members member in EnumClass -> True or False - protection from

Re: [Python-Dev] What is the design purpose of metaclasses vs code generating decorators? (was Re: PEP 557: Data Classes)

2017-10-14 Thread Nick Coghlan
On 15 October 2017 at 01:00, Martin Teichmann wrote: > While I am not worried about the poor computers having to do a lot of > work creating a throwaway class, I do see the problem with the new > super. What I would like to see is something like the @wraps decorator >

Re: [Python-Dev] What is the design purpose of metaclasses vs code generating decorators? (was Re: PEP 557: Data Classes)

2017-10-14 Thread Martin Teichmann
>> I do worry that things like your autoslots decorator example might be >> problematic because they create a new class, throwing away a lot of work >> that was already done. But perhaps the right way to address this would be >> to move the decision about the instance layout to a later phase? (Not

Re: [Python-Dev] What is the design purpose of metaclasses vs code generating decorators? (was Re: PEP 557: Data Classes)

2017-10-14 Thread Martin Teichmann
> Things that will not work if Enum does not have a metaclass: > > list(EnumClass) -> list of enum members > dir(EnumClass) -> custom list of "interesting" items > len(EnumClass) -> number of members > member in EnumClass -> True or False > > - protection from adding, deleting, and changing

Re: [Python-Dev] What is the design purpose of metaclasses vs code generating decorators? (was Re: PEP 557: Data Classes)

2017-10-13 Thread Random832
On Fri, Oct 13, 2017, at 02:30, Nick Coghlan wrote: > Metaclasses currently tend to serve two distinct purposes: > > 1. Actually altering the runtime behaviour of a class and its children >in non-standard ways (e.g. enums, ABCs, ORMs) > 2. Boilerplate reduction in class definitions, reducing

Re: [Python-Dev] What is the design purpose of metaclasses vs code generating decorators? (was Re: PEP 557: Data Classes)

2017-10-13 Thread Tin Tvrtković
> > Date: Fri, 13 Oct 2017 08:57:00 -0700 > From: Guido van Rossum > To: Martin Teichmann > Cc: Python-Dev > Subject: Re: [Python-Dev] What is the design purpose of metaclasses vs > code generating decorators? (was Re:

Re: [Python-Dev] What is the design purpose of metaclasses vs code generating decorators? (was Re: PEP 557: Data Classes)

2017-10-13 Thread Ethan Furman
On 10/13/2017 02:35 AM, Martin Teichmann wrote: Metaclasses currently tend to serve two distinct purposes: 1. Actually altering the runtime behaviour of a class and its children in non-standard ways (e.g. enums, ABCs, ORMs) 2. Boilerplate reduction in class definitions, reducing the amount of

Re: [Python-Dev] What is the design purpose of metaclasses vs code generating decorators? (was Re: PEP 557: Data Classes)

2017-10-13 Thread Guido van Rossum
This is food for thought. I'll have to let it sink in a bit, but you may be on to something. Since the question was asked at some point, yes, metaclasses are much older than class decorators. At some point I found the book Putting Metaclasses to Work by Ira Forman and Scott Danforth (

Re: [Python-Dev] What is the design purpose of metaclasses vs code generating decorators? (was Re: PEP 557: Data Classes)

2017-10-13 Thread Nick Coghlan
On 13 October 2017 at 19:35, Martin Teichmann wrote: > > Metaclasses currently tend to serve two distinct purposes: > > > > 1. Actually altering the runtime behaviour of a class and its children in > > non-standard ways (e.g. enums, ABCs, ORMs) > > 2. Boilerplate

Re: [Python-Dev] What is the design purpose of metaclasses vs code generating decorators? (was Re: PEP 557: Data Classes)

2017-10-13 Thread Koos Zevenhoven
While I really can't continue to be active in this discussion now [*], here are some thoughts based on observations I made: These three PEPs are all essentially solving an occurrence of the same problem: PEP 549 Instance descriptors PEP 562 Module __getattr__ PEP 560 Core support for generic

Re: [Python-Dev] What is the design purpose of metaclasses vs code generating decorators? (was Re: PEP 557: Data Classes)

2017-10-13 Thread Martin Teichmann
> Metaclasses currently tend to serve two distinct purposes: > > 1. Actually altering the runtime behaviour of a class and its children in > non-standard ways (e.g. enums, ABCs, ORMs) > 2. Boilerplate reduction in class definitions, reducing the amount of code > you need to write as the author of

[Python-Dev] What is the design purpose of metaclasses vs code generating decorators? (was Re: PEP 557: Data Classes)

2017-10-13 Thread Nick Coghlan
On 13 October 2017 at 04:21, Martin Teichmann wrote: > For me, the dataclasses were a typical example for inheritance, to be > more precise, for metaclasses. I was astonished to see them > implemented using decorators, and I was not the only one, citing > Guido: > > > I