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
1e93b060
Commit
1e93b060
authored
May 15, 2013
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
complain about "global __class__" in a class body (closes #17983)
parent
c032f16d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
0 deletions
+13
-0
Lib/test/test_scope.py
Lib/test/test_scope.py
+4
-0
Misc/NEWS
Misc/NEWS
+3
-0
Python/symtable.c
Python/symtable.c
+6
-0
No files found.
Lib/test/test_scope.py
View file @
1e93b060
...
...
@@ -743,6 +743,10 @@ class ScopeTests(unittest.TestCase):
del
tester
self
.
assertIsNone
(
ref
())
def
test__Class__Global
(
self
):
s
=
"class X:
\
n
global __class__
\
n
def f(self): super()"
self
.
assertRaises
(
SyntaxError
,
exec
,
s
)
def
test_main
():
run_unittest
(
ScopeTests
)
...
...
Misc/NEWS
View file @
1e93b060
...
...
@@ -12,6 +12,9 @@ What's New in Python 3.3.3 release candidate 1?
Core and Builtins
-----------------
- Issue #17983: Raise a SyntaxError for a ``global __class__`` statement in a
class body.
- Issue #17927: Frame objects kept arguments alive if they had been copied into
a cell, even if the cell was cleared.
...
...
Python/symtable.c
View file @
1e93b060
...
...
@@ -1236,6 +1236,12 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
asdl_seq
*
seq
=
s
->
v
.
Global
.
names
;
for
(
i
=
0
;
i
<
asdl_seq_LEN
(
seq
);
i
++
)
{
identifier
name
=
(
identifier
)
asdl_seq_GET
(
seq
,
i
);
if
(
st
->
st_cur
->
ste_type
==
ClassBlock
&&
!
PyUnicode_CompareWithASCIIString
(
name
,
"__class__"
))
{
PyErr_SetString
(
PyExc_SyntaxError
,
"cannot make __class__ global"
);
PyErr_SyntaxLocationEx
(
st
->
st_filename
,
s
->
lineno
,
s
->
col_offset
);
return
0
;
}
long
cur
=
symtable_lookup
(
st
,
name
);
if
(
cur
<
0
)
VISIT_QUIT
(
st
,
0
);
...
...
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