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
Xavier Thompson
cython
Commits
7f22634d
Commit
7f22634d
authored
Sep 04, 2011
by
Vitja Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Disallow final cpdef methods in non-final extension type
parent
128eb184
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
15 deletions
+26
-15
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+6
-2
tests/errors/final_methods.pyx
tests/errors/final_methods.pyx
+1
-4
tests/run/final_method_T586.pyx
tests/run/final_method_T586.pyx
+19
-9
No files found.
Cython/Compiler/Nodes.py
View file @
7f22634d
...
...
@@ -2244,8 +2244,12 @@ class DefNode(FuncDefNode):
#print "DefNode.declare_pyfunction:", self.name, "in", env ###
name
=
self
.
name
entry
=
env
.
lookup_here
(
name
)
if
entry
and
entry
.
type
.
is_cfunction
and
not
entry
.
is_builtin_cmethod
and
not
self
.
is_wrapper
:
warning
(
self
.
pos
,
"Overriding cdef method with def method."
,
5
)
if
entry
:
if
entry
.
is_final_cmethod
and
not
env
.
parent_type
.
is_final_type
:
error
(
self
.
pos
,
"Only final type could have final cpdef method"
)
if
(
entry
.
type
.
is_cfunction
and
not
entry
.
is_builtin_cmethod
and
not
self
.
is_wrapper
):
warning
(
self
.
pos
,
"Overriding cdef method with def method."
,
5
)
entry
=
env
.
declare_pyfunction
(
name
,
self
.
pos
,
allow_redefine
=
not
self
.
is_wrapper
)
self
.
entry
=
entry
prefix
=
env
.
next_id
(
env
.
scope_prefix
)
...
...
tests/errors/final_methods.pyx
View file @
7f22634d
...
...
@@ -16,10 +16,7 @@ cdef class SubType(BaseClass):
cdef
cdef
_method
(
self
):
pass
cpdef
cpdef
_method
(
self
):
pass
_ERRORS
=
"""
11:10: Only final type could have final cpdef method
16:9: Overriding final methods is not allowed
19:10: Overriding final methods is not allowed
"""
tests/run/final_method_T586.pyx
View file @
7f22634d
...
...
@@ -3,21 +3,20 @@
cimport
cython
cdef
class
FinalMethods
(
object
):
@
cython
.
final
cdef
class
FinalType
(
object
):
"""
>>> obj = Final
Methods
()
>>> obj = Final
Type
()
>>> obj.test_cdef()
>>> obj.test_cpdef()
"""
@
cython
.
test_assert_path_exists
(
"//CFuncDefNode[@entry.is_final_cmethod=True]"
)
@
cython
.
final
cdef
cdef
_method
(
self
):
pass
@
cython
.
test_assert_path_exists
(
"//CFuncDefNode[@entry.is_final_cmethod=True]"
)
@
cython
.
test_fail_if_path_exists
(
"//CFuncDefNode//OverrideCheckNode"
)
@
cython
.
final
cpdef
cpdef
_method
(
self
):
pass
...
...
@@ -30,16 +29,27 @@ cdef class FinalMethods(object):
self
.
cpdef
_method
()
cdef
class
SubType
(
FinalMethods
):
cdef
class
BaseTypeWithFinalMethods
(
object
):
"""
>>> obj =
SubType
()
>>> obj =
BaseTypeWithFinalMethods
()
>>> obj.test_cdef()
>>> obj.test_cpdef()
"""
@
cython
.
test_assert_path_exists
(
"//CFuncDefNode[@entry.is_final_cmethod=True]"
)
@
cython
.
final
cdef
cdef
_method
(
self
):
pass
@
cython
.
test_assert_path_exists
(
"//AttributeNode[@entry.is_final_cmethod=True]"
)
def
test_cdef
(
self
):
self
.
cdef
_method
()
cdef
class
SubType
(
BaseTypeWithFinalMethods
):
"""
>>> obj = SubType()
>>> obj.test_cdef()
"""
@
cython
.
test_assert_path_exists
(
"//AttributeNode[@entry.is_final_cmethod=True]"
)
def
test_c
p
def
(
self
):
self
.
c
p
def
_method
()
def
test_cdef
(
self
):
self
.
cdef
_method
()
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