homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Fixer for new metaclass syntax is needed
Type: behavior Stage:
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: jackdied Nosy List: benjamin.peterson, brett.cannon, collinwinter, jackdied, rhettinger
Priority: critical Keywords: 26backport, patch

Created on 2008年03月17日 19:54 by brett.cannon, last changed 2022年04月11日 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
fix_metaclass.patch jackdied, 2008年03月19日 23:58
fix_metaclass.patch jackdied, 2008年03月20日 23:01
fix_metaclass.patch jackdied, 2008年07月31日 20:46
Messages (12)
msg63743 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2008年03月17日 19:54
* new metaclass syntax (removing __metaclass__?)
 - __metaclass__ = type at global level disappear
 - __metaclass__ = <anything else> should generate warning
 - __metaclass__ = <something> within a class should use new syntax
 - class __metaclass__ should be warned about
 - any other use of __metaclass__ should be warned about
msg63764 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2008年03月17日 20:38
Does the old way still work in 3.0? If so, I don't think we should have
a fixer.
msg64117 - (view) Author: Collin Winter (collinwinter) * (Python committer) Date: 2008年03月19日 22:58
A quick test indicates that the old way doesn't work anymore.
msg64127 - (view) Author: Jack Diederich (jackdied) * (Python committer) Date: 2008年03月19日 23:58
Here is a partial implementation. It doesn't warn about __metaclass__
at the module level and doesn't handle multiple __metaclass__
assignements in one class. tests pending.
msg64220 - (view) Author: Jack Diederich (jackdied) * (Python committer) Date: 2008年03月20日 23:01
New patch that does more. Collin, could you take a look at the fixer? 
I listed some stumbling blocks at the top (and at least one bug in
2to3). The fixer seems to work fine on actual files but the unit tests
that use strings do nothing. Thanks.
msg70462 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008年07月31日 01:59
Ping
msg70524 - (view) Author: Jack Diederich (jackdied) * (Python committer) Date: 2008年07月31日 17:25
Thanks for the ping. I just rewrote the patch from scratch and it
handles corner cases (of which there are many in the parse tree) better.
 I'll upload/checkin sometime today.
msg70530 - (view) Author: Jack Diederich (jackdied) * (Python committer) Date: 2008年07月31日 20:46
The new patch works and handles all the corner cases I could think of. 
I tried to comment the heck out of it because it does a lot of manual
walking and manipulation of the syntax tree.
This only handles __metaclass__ inside classes. I wasn't sure what to
do with __metaclass__ at the module level (which is now a NOP, I think).
msg71692 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008年08月21日 22:06
Good work on the patch! It looks pretty good. I'm attaching a patch with
a few minor changes. I don't really understand the need for
fixup_parse_tree, since I see in the Grammar that a suite is required
for every classdef.
msg71718 - (view) Author: Jack Diederich (jackdied) * (Python committer) Date: 2008年08月22日 02:38
Benjamin, the 2to3 parse tree straddles the 2.x Grammar and 3.x Grammar
(it's its own thing) which is why fixup_parse_tree is there. From the
docstring:
 one-line classes don't get a suite in the parse tree so we add one to
normalize the tree
The 2to3 parser is very line oriented - only the try/except logic uses
blocks (I think).
There haven't been any objection so I've assigned this to myself and
I'll check it in and close it soonish.
msg71719 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008年08月22日 02:45
On Thu, Aug 21, 2008 at 9:38 PM, Jack Diederich <report@bugs.python.org> wrote:
>
> Jack Diederich <jackdied@gmail.com> added the comment:
>
> Benjamin, the 2to3 parse tree straddles the 2.x Grammar and 3.x Grammar
> (it's its own thing) which is why fixup_parse_tree is there. From the
> docstring:
> one-line classes don't get a suite in the parse tree so we add one to
> normalize the tree
> The 2to3 parser is very line oriented - only the try/except logic uses
> blocks (I think).
Yes. Sorry that was a brain seg fault. :)
>
> There haven't been any objection so I've assigned this to myself and
> I'll check it in and close it soonish.
Add an example example.py while you're at it.
>
> ----------
> assignee: collinwinter -> jackdied
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue2366>
> _______________________________________
>
msg73163 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008年09月13日 02:32
Added in r66438.
One open issue is that the comment is lost in the following example:
class X:
 __metaclass__ = Meta # Spam
History
Date User Action Args
2022年04月11日 14:56:32adminsetgithub: 46619
2008年09月13日 02:32:49benjamin.petersonsetstatus: open -> closed
resolution: fixed
messages: + msg73163
2008年08月22日 02:45:36benjamin.petersonsetmessages: + msg71719
2008年08月22日 02:38:06jackdiedsetassignee: collinwinter -> jackdied
messages: + msg71718
2008年08月21日 22:06:49benjamin.petersonsetmessages: + msg71692
2008年07月31日 20:46:56jackdiedsetfiles: + fix_metaclass.patch
messages: + msg70530
2008年07月31日 17:25:57jackdiedsetmessages: + msg70524
2008年07月31日 01:59:31benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg70462
2008年03月20日 23:01:16jackdiedsetfiles: + fix_metaclass.patch
messages: + msg64220
2008年03月19日 23:58:49jackdiedsetfiles: + fix_metaclass.patch
keywords: + patch
messages: + msg64127
2008年03月19日 22:58:37collinwintersetmessages: + msg64117
2008年03月17日 20:38:02rhettingersetnosy: + rhettinger
messages: + msg63764
2008年03月17日 20:16:36brett.cannonsetpriority: release blocker -> critical
2008年03月17日 20:11:51jackdiedsetnosy: + jackdied
2008年03月17日 19:54:31brett.cannoncreate

AltStyle によって変換されたページ (->オリジナル) /