Issue 2366: Fixer for new metaclass syntax is needed
Issue2366
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) * ![]() |
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) * ![]() |
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) * ![]() |
Date: 2008-03-19 22:58 | |
A quick test indicates that the old way doesn't work anymore. |
|||
| msg64127 - (view) | Author: Jack Diederich (jackdied) * ![]() |
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) * ![]() |
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) * ![]() |
Date: 2008-07-31 01:59 | |
Ping |
|||
| msg70524 - (view) | Author: Jack Diederich (jackdied) * ![]() |
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) * ![]() |
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) * ![]() |
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) * ![]() |
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) * ![]() |
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) * ![]() |
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:32 | admin | set | github: 46619 |
| 2008-09-13 02:32:49 | benjamin.peterson | set | status: open -> closed resolution: fixed messages: + msg73163 |
| 2008-08-22 02:45:36 | benjamin.peterson | set | messages: + msg71719 |
| 2008-08-22 02:38:06 | jackdied | set | assignee: collinwinter -> jackdied messages: + msg71718 |
| 2008-08-21 22:06:49 | benjamin.peterson | set | messages: + msg71692 |
| 2008-07-31 20:46:56 | jackdied | set | files:
+ fix_metaclass.patch messages: + msg70530 |
| 2008-07-31 17:25:57 | jackdied | set | messages: + msg70524 |
| 2008-07-31 01:59:31 | benjamin.peterson | set | nosy:
+ benjamin.peterson messages: + msg70462 |
| 2008-03-20 23:01:16 | jackdied | set | files:
+ fix_metaclass.patch messages: + msg64220 |
| 2008-03-19 23:58:49 | jackdied | set | files:
+ fix_metaclass.patch keywords: + patch messages: + msg64127 |
| 2008-03-19 22:58:37 | collinwinter | set | messages: + msg64117 |
| 2008-03-17 20:38:02 | rhettinger | set | nosy:
+ rhettinger messages: + msg63764 |
| 2008-03-17 20:16:36 | brett.cannon | set | priority: release blocker -> critical |
| 2008-03-17 20:11:51 | jackdied | set | nosy: + jackdied |
| 2008-03-17 19:54:31 | brett.cannon | create | |
