Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #7456
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeder.news-service.com!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'bug': 0.02; 'passes': 0.05; 'exception,': 0.07; 'figures': 0.07; 'terry': 0.07; 'type,': 0.07; 'python': 0.08; 'dict': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'pm,': 0.10; 'subject:error': 0.11; '>>>': 0.12; 'def': 0.12; 'am,': 0.14; 'broken': 0.14; 'described': 0.14; 'wrote:': 0.14; 'bases,': 0.16; 'calculation': 0.16; 'creation.': 0.16; 'discarded': 0.16; 'docstring': 0.16; 'forwards': 0.16; 'implied.': 0.16; 'looping.': 0.16; 'metaclass': 0.16; 'metaclasses': 0.16; 'patch,': 0.16; 'reedy': 0.16; 'subclasses.': 0.16; 'jan': 0.20; 'header:In-Reply-To:1': 0.21; 'loop': 0.22; 'code.': 0.22; '(or': 0.24; 'code': 0.24; 'changed': 0.25; 'specified': 0.26; 'pass': 0.27; 'example': 0.27; 'thanks': 0.28; 'raise': 0.28; 'sat,': 0.29; 'sorry,': 0.29; 'class': 0.29; 'version': 0.29; 'least': 0.30; 'second': 0.30; 'confused': 0.30; 'steven': 0.32; 'header:X-Complaints-To:1': 0.32; 'to:addr:python- list': 0.33; 'there': 0.35; 'header:User-Agent:1': 0.35; "d'aprano": 0.35; 'doc': 0.35; 'fails': 0.35; 'instances': 0.35; 'skip:@ 10': 0.35; 'skip:{ 10': 0.35; 'test': 0.35; 'probably': 0.36; 'issue': 0.37; 'another': 0.37; 'think': 0.38; 'received:org': 0.38; 'but': 0.38; 'docs': 0.38; 'subject:: ': 0.38; 'some': 0.38; 'called': 0.39; 'empty': 0.39; 'header:Mime- Version:1': 0.39; 'either': 0.39; 'to:addr:python.org': 0.39; 'report': 0.40; 'getting': 0.40; 'really': 0.40; 'happen': 0.60; 'results': 0.60; 'within': 0.60; 'back': 0.63; 'details': 0.64; '11:34': 0.84; 'that),': 0.91; 'notice.': 0.96 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Terry Reedy <tjreedy@udel.edu> |
| Subject | Re: Recursion error in metaclass |
| Date | Sat, 11 Jun 2011 15:39:34 -0400 |
| References | <4df2e251$0$30002$c3e8da3$5496439d@news.astraweb.com> <mailman.124.1307770420.11593.python-list@python.org> <4df353b4$0$30002$c3e8da3$5496439d@news.astraweb.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | rain.gmane.org |
| User-Agent | Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110414 Lightning/1.0b2 Thunderbird/3.1.10 |
| In-Reply-To | <4df353b4$0$30002$c3e8da3$5496439d@news.astraweb.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.134.1307821190.11593.python-list@python.org> (permalink) |
| Lines | 44 |
| NNTP-Posting-Host | 82.94.164.166 |
| X-Trace | 1307821190 news.xs4all.nl 49176 [::ffff:82.94.164.166]:48521 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:7456 |
Show key headers only | View raw
On 6/11/2011 7:38 AM, Steven D'Aprano wrote:
> On Sat, 11 Jun 2011 01:33:25 -0400, Terry Reedy wrote:
>
>> On 6/10/2011 11:34 PM, Steven D'Aprano wrote:
>>> I have a metaclass in Python 3.1:
>>>
>>> class MC1(type):
>>> @staticmethod
>>> def get_mro(bases):
>>> print('get_mro called')
>>> return type('K', bases, {}).__mro__[1:]
>>
>> The call to type figures out the proper metaclass from bases and
>> forwards the call to that (or to its __new__ method).
> [...]
>> Since uou do not pass dict to get_mro. it passes {} to type and MC1 and
>> the test for docstring fails and the loop is broken and the empty class
>> is discarded after getting its mro.
>
> Thanks for the explanation. You confused me for a while talking about
> MC1, because that's the metaclass that *doesn't* raise an exception, but
Sorry, you probably changed that to MC2 for the second example and I did
not notice. The point is that when either version calls get_mro and
type, types calls back to the same metaclass, so that unguarding the
call to get_mro results in looping.
> I think I see the issue now.
What may not be obvious from the docs is that the metaclass calculation
described in the doc section on class statements is carried out within
type.__new__ (or after a possible patch, called from within that), so
that type calls are really "a dynamic form of the class statement" even
when another another metaclass is specified or implied. "Return a new
type object." includes instances of type subclasses. I am not sure what
happens with metaclasses that are not type subclasses. There is at least
one bug report about the metaclass calculation, which is why I happen to
have read the typeobject.__new__ code. But I have not read the
build-class code and all the details of class creation. So I may have
some of the details above wrong.
--
Terry Jan Reedy
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Recursion error in metaclass Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-11 03:34 +0000
Re: Recursion error in metaclass Terry Reedy <tjreedy@udel.edu> - 2011-06-11 01:33 -0400
Re: Recursion error in metaclass Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-11 11:38 +0000
Re: Recursion error in metaclass Terry Reedy <tjreedy@udel.edu> - 2011-06-11 15:39 -0400
Re: Recursion error in metaclass Daniel Urban <urban.dani@gmail.com> - 2011-06-11 22:51 +0200
csiph-web