msg171323 - (view) |
Author: Raymond Hettinger (rhettinger) *  |
Date: 2012-09-25 23:20 |
Since inheritance is more commonplace and more easily understood than __metaclass__, the abc module would benefit from a simple helper class: class ABC(metaclass=ABCMeta): pass From a user's point-of-view, writing an abstract base call becomes simpler and clearer: from abc import ABC, abstractmethod class Vector(ABC): @abstractmethod def __iter__(self): pass def dot(self, other): 'Compute a dot product' return sum(map(operator.mul, self, other)) Notice that this class seems less mysterious because it inherits from ABC rather than using __metaclass__=ABCMeta. Also note, it has become a reasonably common practice for metaclass writers to put the __metaclass__ assignment in a class and have it get inherited rather than requiring users do the metaclass assignment themselves. |
|
|
msg171331 - (view) |
Author: Mark Dickinson (mark.dickinson) *  |
Date: 2012-09-26 07:52 |
+1 |
|
|
msg171501 - (view) |
Author: Éric Araujo (eric.araujo) *  |
Date: 2012-09-28 16:25 |
Agreed. |
|
|
msg171658 - (view) |
Author: Antoine Pitrou (pitrou) *  |
Date: 2012-09-30 18:36 |
It looks slightly better, but it would also violate "there is one obvious way to do it". |
|
|
msg171668 - (view) |
Author: Guido van Rossum (gvanrossum) *  |
Date: 2012-09-30 20:07 |
In practice this is indeed how most users of met a classes do it. E.g. Django. So, +1. --Guido van Rossum (sent from Android phone) On Sep 30, 2012 11:36 AM, "Antoine Pitrou" <report@bugs.python.org> wrote: > > Antoine Pitrou added the comment: > > It looks slightly better, but it would also violate "there is one obvious > way to do it". > > ---------- > nosy: +gvanrossum, pitrou > > _______________________________________ > Python tracker <report@bugs.python.org> > <http://bugs.python.org/issue16049> > _______________________________________ > |
|
|
msg176658 - (view) |
Author: Bruno Dupuis (bruno.dupuis) |
Date: 2012-11-29 16:02 |
This solution hides the risk of metaclass conflicts, as the user did not explicitly set the metaclass. IMO, this risk should be clearly told in the Doc. |
|
|
msg177068 - (view) |
Author: Éric Araujo (eric.araujo) *  |
Date: 2012-12-07 05:49 |
Bruno: do you want to propose an idea for the doc part? Or even a full patch for this request? |
|
|
msg177082 - (view) |
Author: Bruno Dupuis (bruno.dupuis) |
Date: 2012-12-07 12:41 |
Éric, here is a full patch. I hope the doc isn't too confuse. I think we lack a word meaning 'has XXX as metaclass', we should imagine a term for that. |
|
|
msg177248 - (view) |
Author: Raymond Hettinger (rhettinger) *  |
Date: 2012-12-10 01:47 |
+1 The patch looks fine. Éric do you want to apply it? |
|
|
msg177406 - (view) |
Author: Andrew Svetlov (asvetlov) *  |
Date: 2012-12-13 13:09 |
LGTM |
|
|
msg177412 - (view) |
Author: Éric Araujo (eric.araujo) *  |
Date: 2012-12-13 16:30 |
Feel free to commit the patch Andrew. You may want to document the new ABC class before the ABCMeta, as we expect that subclassing will become the preferred way. |
|
|
msg177420 - (view) |
Author: Roundup Robot (python-dev)  |
Date: 2012-12-13 17:09 |
New changeset 9347869d1066 by Andrew Svetlov in branch 'default': Issue #16049: add abc.ABC helper class. http://hg.python.org/cpython/rev/9347869d1066 |
|
|
msg177424 - (view) |
Author: Andrew Svetlov (asvetlov) *  |
Date: 2012-12-13 17:14 |
Done. I prefer to leave existing class order in documentation. In general I agree with Eric that ABC should be before ABCMeta in the doc but now it has formalized as helper for metaclass with very short documentation. To put ABC first we need to transplate almost all content of ABCMeta doc int ABC. If somebody want to do it — please create new issue and feel free to make a patch. |
|
|
msg177425 - (view) |
Author: Andrew Svetlov (asvetlov) *  |
Date: 2012-12-13 17:14 |
Thanks, Bruno. |
|
|