Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
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
Boxiang Sun
Pyston
Commits
e95b1c58
Commit
e95b1c58
authored
Apr 06, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove the namedtuple workaround
Fix a couple misc issues along the way
parent
6af09380
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
72 additions
and
33 deletions
+72
-33
from_cpython/Lib/collections.py
from_cpython/Lib/collections.py
+0
-32
src/analysis/scoping_analysis.cpp
src/analysis/scoping_analysis.cpp
+1
-1
src/core/ast.cpp
src/core/ast.cpp
+4
-0
test/tests/collections_test.py
test/tests/collections_test.py
+6
-0
test/tests/exec_in_test.py
test/tests/exec_in_test.py
+7
-0
test/tests/exec_syntax_error.py
test/tests/exec_syntax_error.py
+30
-0
test/tests/exec_syntax_error2.py
test/tests/exec_syntax_error2.py
+18
-0
test/tests/namedtuple_name.py
test/tests/namedtuple_name.py
+6
-0
No files found.
from_cpython/Lib/collections.py
View file @
e95b1c58
...
...
@@ -407,38 +407,6 @@ def namedtuple(typename, field_names, verbose=False, rename=False):
return
result
# Pyston change: use this hacky / slow? version of namedtuple while we work
# on exec support
def
namedtuple
(
name
,
fields
):
if
isinstance
(
fields
,
str
):
fields
=
fields
.
split
()
assert
isinstance
(
fields
,
list
)
for
f
in
fields
:
assert
isinstance
(
f
,
str
)
class
NamedTuple
(
object
):
def
__init__
(
self
,
*
args
):
assert
len
(
args
)
==
len
(
fields
)
for
i
in
xrange
(
len
(
fields
)):
setattr
(
self
,
fields
[
i
],
args
[
i
])
def
__getitem__
(
self
,
idx
):
assert
0
<=
idx
<
len
(
fields
)
return
getattr
(
self
,
fields
[
idx
])
def
__repr__
(
self
):
s
=
name
+
"("
first
=
True
for
f
in
fields
:
if
not
first
:
s
+=
", "
first
=
False
s
+=
"%s=%r"
%
(
f
,
getattr
(
self
,
f
))
s
+=
")"
return
s
return
NamedTuple
########################################################################
### Counter
########################################################################
...
...
src/analysis/scoping_analysis.cpp
View file @
e95b1c58
...
...
@@ -657,7 +657,7 @@ public:
}
bool
visit_exec
(
AST_Exec
*
node
)
override
{
if
(
node
->
loc
als
==
NULL
)
{
if
(
node
->
glob
als
==
NULL
)
{
doBareExec
(
node
);
}
return
false
;
...
...
src/core/ast.cpp
View file @
e95b1c58
...
...
@@ -462,6 +462,10 @@ void AST_Exec::accept(ASTVisitor* v) {
if
(
body
)
body
->
accept
(
v
);
if
(
globals
)
globals
->
accept
(
v
);
if
(
locals
)
locals
->
accept
(
v
);
}
void
AST_Exec
::
accept_stmt
(
StmtVisitor
*
v
)
{
...
...
test/tests/collections_test.py
View file @
e95b1c58
...
...
@@ -13,3 +13,9 @@ d = collections.defaultdict(lambda: [])
print
d
[
1
]
d
[
2
].
append
(
3
)
print
sorted
(
d
.
items
())
NT
=
collections
.
namedtuple
(
"NT"
,
[
"field1"
,
"field2"
])
print
NT
.
__name__
n
=
NT
(
1
,
"hi"
)
print
n
.
field1
,
n
.
field2
,
len
(
n
),
list
(
n
),
n
[
0
],
n
[
-
1
]
print
n
test/tests/exec_in_test.py
View file @
e95b1c58
...
...
@@ -118,3 +118,10 @@ exec s
a
=
5
exec
"""print eval('a')"""
in
{
'a'
:
6
},
{}
exec
"""exec 'print a' """
in
{
'a'
:
6
},
{}
# test ordering:
def
show
(
obj
,
msg
):
print
msg
return
obj
exec
show
(
"print 'in exec'"
,
"body"
)
in
show
(
None
,
"globals"
),
show
(
None
,
"locals"
)
test/tests/exec_syntax_error.py
0 → 100644
View file @
e95b1c58
s
=
"""
def f():
a = 1
exec "a = 2"
def g():
print a
g()
f()
"""
try
:
exec
s
except
Exception
as
e
:
print
repr
(
e
)
s
=
"""
def f():
a = 1
d = {}
exec "a = 2" in {}, d
def g():
print a
g()
print d
f()
"""
try
:
exec
s
except
Exception
as
e
:
print
repr
(
e
)
test/tests/exec_syntax_error2.py
0 → 100644
View file @
e95b1c58
# expected: fail
# - surprisingly, this is allowed? doesn't seem very different from exec_syntax_error.py
# We print 1, CPython and PyPy print 2
s
=
"""
def f():
a = 1
exec "a = 2" in None
def g():
print a
g()
f()
"""
try
:
exec
s
except
Exception
as
e
:
print
repr
(
e
)
test/tests/namedtuple_name.py
0 → 100644
View file @
e95b1c58
# expected: fail
# - needs sys._getframe
import
collections
NT
=
collections
.
namedtuple
(
"NT"
,
[
"field1"
,
"field2"
])
print
NT
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