Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
b211d1e8
Commit
b211d1e8
authored
Nov 07, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support 'global' in Python class body
--HG-- rename : tests/run/ass2global.pyx => tests/run/ass2global.py
parent
3421e034
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
0 deletions
+17
-0
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+8
-0
tests/run/ass2global.py
tests/run/ass2global.py
+9
-0
No files found.
Cython/Compiler/Symtab.py
View file @
b211d1e8
...
@@ -1741,6 +1741,14 @@ class PyClassScope(ClassScope):
...
@@ -1741,6 +1741,14 @@ class PyClassScope(ClassScope):
# right thing to do
# right thing to do
self
.
entries
[
name
]
=
entry
self
.
entries
[
name
]
=
entry
def
declare_global
(
self
,
name
,
pos
):
# Pull entry from global scope into local scope.
if
self
.
lookup_here
(
name
):
warning
(
pos
,
"'%s' redeclared "
,
0
)
else
:
entry
=
self
.
global_scope
().
lookup_target
(
name
)
self
.
entries
[
name
]
=
entry
def
add_default_value
(
self
,
type
):
def
add_default_value
(
self
,
type
):
return
self
.
outer_scope
.
add_default_value
(
type
)
return
self
.
outer_scope
.
add_default_value
(
type
)
...
...
tests/run/ass2global.py
x
→
tests/run/ass2global.py
View file @
b211d1e8
...
@@ -4,13 +4,22 @@ __doc__ = u"""
...
@@ -4,13 +4,22 @@ __doc__ = u"""
>>> f(42)
>>> f(42)
>>> getg()
>>> getg()
42
42
>>> global_in_class
9
"""
"""
g
=
5
g
=
5
def
f
(
a
):
def
f
(
a
):
global
g
global
g
g
=
a
g
=
a
def
getg
():
def
getg
():
return
g
return
g
class
Test
(
object
):
global
global_in_class
global_in_class
=
9
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