[Python-3000] Metaclasses in Py3K (original) (raw)
Phillip J. Eby pje at telecommunity.com
Sun Dec 17 03:10:22 CET 2006
- Previous message: [Python-3000] Metaclasses in Py3K
- Next message: [Python-3000] Metaclasses in Py3K
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
At 12:53 PM 12/17/2006 +1300, Greg Ewing wrote:
The main use case for all this seems to be that some metaclasses would like to know the order in which attributes were defined. So here's an alternative proposal: Leave the syntax the way it is, and always use a specialised dict that remembers the order of definition. The metaclass can then use that information or ignore it as it wishes.
Pro: ordered dicts are an often-requested feature anyway
Con: doesn't allow errors to occur at the line where they really are
IOW, a metaclass that validates assignments can't complain about a bad value at the point where it's assigned. This is an annoyance now because an error occurring in the metaclass init or new looks like it's happening at the 'class' statement currently.
So, if we have to have some kind of special dictionary-like thing, I prefer using one that sets attributes on the class object, as this allows you to catch errors at the line where they occur, in the body of the class.
This approach also has the added side benefit of forcing us to clean up a few quirks in the object/class model. :)
- Previous message: [Python-3000] Metaclasses in Py3K
- Next message: [Python-3000] Metaclasses in Py3K
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]