Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
7e0dbfbb
Commit
7e0dbfbb
authored
Mar 12, 2012
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
give the AST class a __dict__
parent
61a4161d
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
6 deletions
+35
-6
Lib/test/test_ast.py
Lib/test/test_ast.py
+3
-0
Misc/NEWS
Misc/NEWS
+2
-0
Parser/asdl_c.py
Parser/asdl_c.py
+15
-3
Python/Python-ast.c
Python/Python-ast.c
+15
-3
No files found.
Lib/test/test_ast.py
View file @
7e0dbfbb
...
...
@@ -196,6 +196,9 @@ class AST_Tests(unittest.TestCase):
def
test_AST_objects
(
self
):
x
=
ast
.
AST
()
self
.
assertEqual
(
x
.
_fields
,
())
x
.
foobar
=
42
self
.
assertEqual
(
x
.
foobar
,
42
)
self
.
assertEqual
(
x
.
__dict__
[
"foobar"
],
42
)
with
self
.
assertRaises
(
AttributeError
):
x
.
vararg
...
...
Misc/NEWS
View file @
7e0dbfbb
...
...
@@ -10,6 +10,8 @@ What's New in Python 3.3.0 Alpha 2?
Core and Builtins
-----------------
- Give the ast.AST class a __dict__.
- Issue #1469629: Allow cycles through an object'
s
__dict__
slot
to
be
collected
.
(
For
example
if
``
x
.
__dict__
is
x
``).
...
...
Parser/asdl_c.py
View file @
7e0dbfbb
...
...
@@ -603,6 +603,11 @@ class PyTypesVisitor(PickleVisitor):
def
visitModule
(
self
,
mod
):
self
.
emit
(
"""
typedef struct {
PyObject_HEAD;
PyObject *dict;
} AST_object;
static int
ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
{
...
...
@@ -681,10 +686,15 @@ static PyMethodDef ast_type_methods[] = {
{NULL}
};
static PyGetSetDef ast_type_getsets[] = {
{"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict},
{NULL}
};
static PyTypeObject AST_type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"_ast.AST",
sizeof(
PyO
bject),
sizeof(
AST_o
bject),
0,
0, /* tp_dealloc */
0, /* tp_print */
...
...
@@ -711,12 +721,12 @@ static PyTypeObject AST_type = {
0, /* tp_iternext */
ast_type_methods, /* tp_methods */
0, /* tp_members */
0,
/* tp_getset */
ast_type_getsets,
/* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0,
/* tp_dictoffset */
offsetof(AST_object, dict),
/* tp_dictoffset */
(initproc)ast_type_init, /* tp_init */
PyType_GenericAlloc, /* tp_alloc */
PyType_GenericNew, /* tp_new */
...
...
@@ -1185,6 +1195,8 @@ def main(srcfile):
p
=
os
.
path
.
join
(
SRC_DIR
,
str
(
mod
.
name
)
+
"-ast.c"
)
f
=
open
(
p
,
"w"
)
f
.
write
(
auto_gen_msg
)
f
.
write
(
'#include <stddef.h>
\
n
'
)
f
.
write
(
'
\
n
'
)
f
.
write
(
'#include "Python.h"
\
n
'
)
f
.
write
(
'#include "%s-ast.h"
\
n
'
%
mod
.
name
)
f
.
write
(
'
\
n
'
)
...
...
Python/Python-ast.c
View file @
7e0dbfbb
/* File automatically generated by Parser/asdl_c.py. */
#include <stddef.h>
#include "Python.h"
#include "Python-ast.h"
...
...
@@ -453,6 +455,11 @@ static char *withitem_fields[]={
};
typedef
struct
{
PyObject_HEAD
;
PyObject
*
dict
;
}
AST_object
;
static
int
ast_type_init
(
PyObject
*
self
,
PyObject
*
args
,
PyObject
*
kw
)
{
...
...
@@ -531,10 +538,15 @@ static PyMethodDef ast_type_methods[] = {
{
NULL
}
};
static
PyGetSetDef
ast_type_getsets
[]
=
{
{
"__dict__"
,
PyObject_GenericGetDict
,
PyObject_GenericSetDict
},
{
NULL
}
};
static
PyTypeObject
AST_type
=
{
PyVarObject_HEAD_INIT
(
&
PyType_Type
,
0
)
"_ast.AST"
,
sizeof
(
PyO
bject
),
sizeof
(
AST_o
bject
),
0
,
0
,
/* tp_dealloc */
0
,
/* tp_print */
...
...
@@ -561,12 +573,12 @@ static PyTypeObject AST_type = {
0
,
/* tp_iternext */
ast_type_methods
,
/* tp_methods */
0
,
/* tp_members */
0
,
/* tp_getset */
ast_type_getsets
,
/* tp_getset */
0
,
/* tp_base */
0
,
/* tp_dict */
0
,
/* tp_descr_get */
0
,
/* tp_descr_set */
0
,
/* tp_dictoffset */
offsetof
(
AST_object
,
dict
),
/* tp_dictoffset */
(
initproc
)
ast_type_init
,
/* tp_init */
PyType_GenericAlloc
,
/* tp_alloc */
PyType_GenericNew
,
/* tp_new */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment