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
9b57b1c5
Commit
9b57b1c5
authored
Oct 30, 2010
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support for 'final' cdef types using a directive decorator
parent
4fabd474
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
1 deletion
+48
-1
Cython/Compiler/Options.py
Cython/Compiler/Options.py
+2
-0
Cython/Compiler/TypeSlots.py
Cython/Compiler/TypeSlots.py
+3
-1
tests/run/final_cdef_class.pyx
tests/run/final_cdef_class.pyx
+43
-0
No files found.
Cython/Compiler/Options.py
View file @
9b57b1c5
...
...
@@ -81,6 +81,7 @@ directive_defaults = {
# Override types possibilities above, if needed
directive_types
=
{
'final'
:
bool
,
# final cdef classes and methods
'infer_types'
:
bool
,
# values can be True/None/False
}
...
...
@@ -90,6 +91,7 @@ for key, val in directive_defaults.items():
directive_scopes
=
{
# defaults to available everywhere
# 'module', 'function', 'class', 'with statement'
'final'
:
(
'cclass'
,),
# add 'method' in the future
'autotestdict'
:
(
'module'
,),
'test_assert_path_exists'
:
(
'function'
,),
'test_fail_if_path_exists'
:
(
'function'
,),
...
...
Cython/Compiler/TypeSlots.py
View file @
9b57b1c5
...
...
@@ -323,7 +323,9 @@ class TypeFlagsSlot(SlotDescriptor):
# Descriptor for the type flags slot.
def
slot_code
(
self
,
scope
):
value
=
"Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER"
value
=
"Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER"
if
not
scope
.
directives
.
get
(
'final'
,
False
):
value
+=
"|Py_TPFLAGS_BASETYPE"
if
scope
.
needs_gc
():
value
+=
"|Py_TPFLAGS_HAVE_GC"
return
value
...
...
tests/run/final_cdef_class.pyx
0 → 100644
View file @
9b57b1c5
cimport
cython
@
cython
.
final
cdef
class
FinalClass
:
"""
>>> f = FinalClass()
>>> test_final_class(f)
Type tested
>>> try:
... class SubType(FinalClass): pass
... except TypeError:
... print 'PASSED!'
PASSED!
"""
cdef
class
NonFinalClass
:
"""
>>> class SubType(NonFinalClass): pass
>>> s = SubType()
"""
@
cython
.
final
cdef
class
FinalSubClass
(
NonFinalClass
):
"""
>>> f = FinalSubClass()
>>> test_non_final_class(f)
Type tested
>>> try:
... class SubType(FinalSubClass): pass
... except TypeError:
... print 'PASSED!'
PASSED!
"""
def
test_final_class
(
FinalClass
c
):
print
u"Type tested"
def
test_non_final_class
(
NonFinalClass
c
):
print
u"Type tested"
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