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
Gwenaël Samain
cython
Commits
753e262f
Commit
753e262f
authored
7 years ago
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Switch off special methods for closure classes the hard way.
parent
bff0e5cb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
26 deletions
+42
-26
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+27
-25
Cython/Compiler/TypeSlots.py
Cython/Compiler/TypeSlots.py
+6
-0
tests/run/closure_names.pyx
tests/run/closure_names.pyx
+9
-1
No files found.
Cython/Compiler/ModuleNode.py
View file @
753e262f
...
...
@@ -1200,31 +1200,33 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self
.
generate_traverse_function
(
scope
,
code
,
entry
)
if
scope
.
needs_tp_clear
():
self
.
generate_clear_function
(
scope
,
code
,
entry
)
if
scope
.
defines_any
([
"__getitem__"
]):
self
.
generate_getitem_int_function
(
scope
,
code
)
if
scope
.
defines_any
([
"__setitem__"
,
"__delitem__"
]):
self
.
generate_ass_subscript_function
(
scope
,
code
)
if
scope
.
defines_any
([
"__getslice__"
,
"__setslice__"
,
"__delslice__"
]):
warning
(
self
.
pos
,
"__getslice__, __setslice__, and __delslice__ are not supported by Python 3, "
"use __getitem__, __setitem__, and __delitem__ instead"
,
1
)
code
.
putln
(
"#if PY_MAJOR_VERSION >= 3"
)
code
.
putln
(
"#error __getslice__, __setslice__, and __delslice__ not supported in Python 3."
)
code
.
putln
(
"#endif"
)
if
scope
.
defines_any
([
"__setslice__"
,
"__delslice__"
]):
self
.
generate_ass_slice_function
(
scope
,
code
)
if
scope
.
defines_any
([
"__getattr__"
,
"__getattribute__"
]):
self
.
generate_getattro_function
(
scope
,
code
)
if
scope
.
defines_any
([
"__setattr__"
,
"__delattr__"
]):
self
.
generate_setattro_function
(
scope
,
code
)
if
scope
.
defines_any
([
"__get__"
]):
self
.
generate_descr_get_function
(
scope
,
code
)
if
scope
.
defines_any
([
"__set__"
,
"__delete__"
]):
self
.
generate_descr_set_function
(
scope
,
code
)
if
scope
.
defines_any
([
"__dict__"
]):
self
.
generate_dict_getter_function
(
scope
,
code
)
if
scope
.
defines_any
(
TypeSlots
.
richcmp_special_methods
):
self
.
generate_richcmp_function
(
scope
,
code
)
if
not
scope
.
is_closure_class_scope
:
# in closure classes, these are user defined variable names
if
scope
.
defines_any
([
"__getitem__"
]):
self
.
generate_getitem_int_function
(
scope
,
code
)
if
scope
.
defines_any
([
"__setitem__"
,
"__delitem__"
]):
self
.
generate_ass_subscript_function
(
scope
,
code
)
if
scope
.
defines_any
([
"__getslice__"
,
"__setslice__"
,
"__delslice__"
]):
warning
(
self
.
pos
,
"__getslice__, __setslice__, and __delslice__ are not supported by Python 3, "
"use __getitem__, __setitem__, and __delitem__ instead"
,
1
)
code
.
putln
(
"#if PY_MAJOR_VERSION >= 3"
)
code
.
putln
(
"#error __getslice__, __setslice__, and __delslice__ not supported in Python 3."
)
code
.
putln
(
"#endif"
)
if
scope
.
defines_any
([
"__setslice__"
,
"__delslice__"
]):
self
.
generate_ass_slice_function
(
scope
,
code
)
if
scope
.
defines_any
([
"__getattr__"
,
"__getattribute__"
]):
self
.
generate_getattro_function
(
scope
,
code
)
if
scope
.
defines_any
([
"__setattr__"
,
"__delattr__"
]):
self
.
generate_setattro_function
(
scope
,
code
)
if
scope
.
defines_any
([
"__get__"
]):
self
.
generate_descr_get_function
(
scope
,
code
)
if
scope
.
defines_any
([
"__set__"
,
"__delete__"
]):
self
.
generate_descr_set_function
(
scope
,
code
)
if
scope
.
defines_any
([
"__dict__"
]):
self
.
generate_dict_getter_function
(
scope
,
code
)
if
scope
.
defines_any
(
TypeSlots
.
richcmp_special_methods
):
self
.
generate_richcmp_function
(
scope
,
code
)
self
.
generate_property_accessors
(
scope
,
code
)
self
.
generate_method_table
(
scope
,
code
)
self
.
generate_getset_table
(
scope
,
code
)
...
...
This diff is collapsed.
Click to expand it.
Cython/Compiler/TypeSlots.py
View file @
753e262f
...
...
@@ -304,6 +304,8 @@ class MethodSlot(SlotDescriptor):
method_name_to_slot
[
method_name
]
=
self
def
slot_code
(
self
,
scope
):
if
scope
.
is_closure_class_scope
:
return
"0"
entry
=
scope
.
lookup_here
(
self
.
method_name
)
if
entry
and
entry
.
func_cname
:
return
entry
.
func_cname
...
...
@@ -404,6 +406,8 @@ class SyntheticSlot(InternalMethodSlot):
class
RichcmpSlot
(
MethodSlot
):
def
slot_code
(
self
,
scope
):
if
scope
.
is_closure_class_scope
:
return
"0"
entry
=
scope
.
lookup_here
(
self
.
method_name
)
if
entry
and
entry
.
func_cname
:
return
entry
.
func_cname
...
...
@@ -456,6 +460,8 @@ class SuiteSlot(SlotDescriptor):
substructures
.
append
(
self
)
def
is_empty
(
self
,
scope
):
if
scope
.
is_closure_class_scope
:
return
True
for
slot
in
self
.
sub_slots
:
if
slot
.
slot_code
(
scope
)
!=
"0"
:
return
False
...
...
This diff is collapsed.
Click to expand it.
tests/run/closure_names.pyx
View file @
753e262f
...
...
@@ -24,8 +24,16 @@ def func():
def
__dict__
(
a
):
return
'dict'
def
__setitem__
(
x
):
return
'__setitem__'
def
__getslice__
(
x
):
return
'__getslice__'
def
list_from_gen
(
g
):
return
list
(
g
)
# move into closure by using inside of generator expression
return
list_from_gen
([
__eq__
,
__str__
,
__weakref__
,
__new__
,
__dict__
][
i
]
for
i
in
range
(
5
))
return
list_from_gen
(
[
__eq__
,
__str__
,
__weakref__
,
__new__
,
__dict__
,
__setitem__
,
__getslice__
][
i
]
for
i
in
range
(
5
))
This diff is collapsed.
Click to expand it.
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