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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
cython
Commits
4f8e5b0a
Commit
4f8e5b0a
authored
Dec 17, 2010
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix 'nonlocal' for class scope
parent
f39afe8d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
18 deletions
+30
-18
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+11
-0
tests/run/nonlocal_T490.pyx
tests/run/nonlocal_T490.pyx
+19
-18
No files found.
Cython/Compiler/Symtab.py
View file @
4f8e5b0a
...
@@ -1450,6 +1450,17 @@ class PyClassScope(ClassScope):
...
@@ -1450,6 +1450,17 @@ class PyClassScope(ClassScope):
entry
.
is_pyclass_attr
=
1
entry
.
is_pyclass_attr
=
1
return
entry
return
entry
def
declare_nonlocal
(
self
,
name
,
pos
):
# Pull entry from outer scope into local scope
if
self
.
lookup_here
(
name
):
warning
(
pos
,
"'%s' redeclared"
%
name
,
0
)
else
:
entry
=
self
.
lookup
(
name
)
if
entry
is
None
:
error
(
pos
,
"no binding for nonlocal '%s' found"
%
name
)
else
:
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/nonlocal_T490.pyx
View file @
4f8e5b0a
...
@@ -119,24 +119,25 @@ def methods():
...
@@ -119,24 +119,25 @@ def methods():
return
c
()
return
c
()
return
f
return
f
# FIXME: doesn't currently work in class namespace:
def
class_body
(
int
x
,
y
):
"""
## def class_body():
>>> c = class_body(2,99)
## """
>>> c.z
## >>> c = f(0)
(3, 2)
## >>> c.get()
>>> c.x #doctest: +ELLIPSIS
## 1
Traceback (most recent call last):
## >>> c.x #doctest: +ELLIPSIS
AttributeError: ...
## Traceback (most recent call last):
>>> c.y #doctest: +ELLIPSIS
## AttributeError: ...
Traceback (most recent call last):
## """
AttributeError: ...
## def f(x):
"""
## class c:
class
c
(
object
):
## nonlocal x
nonlocal
x
## x += 1
nonlocal
y
## def get(self):
y
=
2
## return x
x
+=
1
## return c()
z
=
x
,
y
return
c
()
def
generator
():
def
generator
():
"""
"""
...
...
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