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
01f48e9e
Commit
01f48e9e
authored
Jun 13, 2018
by
gabrieldemarmiesse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Put the nonecheck example in a separate file in the examples directory to enable testing.
parent
5fadf79e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
19 deletions
+21
-19
docs/examples/tutorial/cdef_classes/nonecheck.pyx
docs/examples/tutorial/cdef_classes/nonecheck.pyx
+19
-0
docs/src/tutorial/cdef_classes.rst
docs/src/tutorial/cdef_classes.rst
+2
-19
No files found.
docs/examples/tutorial/cdef_classes/nonecheck.pyx
0 → 100644
View file @
01f48e9e
# cython: nonecheck=True
# ^^^ Turns on nonecheck globally
import
cython
cdef
class
MyClass
:
pass
# Turn off nonecheck locally for the function
@
cython
.
nonecheck
(
False
)
def
func
():
cdef
MyClass
obj
=
None
try
:
# Turn nonecheck on again for a block
with
cython
.
nonecheck
(
True
):
print
obj
.
myfunc
()
# Raises exception
except
AttributeError
:
pass
print
(
obj
.
myfunc
())
# Hope for a crash!
docs/src/tutorial/cdef_classes.rst
View file @
01f48e9e
...
...
@@ -103,26 +103,9 @@ Some notes on our new implementation of ``evaluate``:
There is a *compiler directive* ``nonecheck`` which turns on checks
for this, at the cost of decreased speed. Here's how compiler directives
are used to dynamically switch on or off ``nonecheck``::
#cython: nonecheck=True
# ^^^ Turns on nonecheck globally
import cython
# Turn off nonecheck locally for the function
@cython.nonecheck(False)
def func():
cdef MyClass obj = None
try:
# Turn nonecheck on again for a block
with cython.nonecheck(True):
print obj.myfunc() # Raises exception
except AttributeError:
pass
print obj.myfunc() # Hope for a crash!
are used to dynamically switch on or off ``nonecheck``:
.. literalinclude:: ../../examples/tutorial/cdef_classes/nonecheck.pyx
Attributes in cdef classes behave differently from attributes in regular classes:
...
...
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