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
1310d1eb
Commit
1310d1eb
authored
Jun 15, 2018
by
scoder
Committed by
GitHub
Jun 15, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2332 from gabrieldemarmiesse/test_cdef_classes_4
Added tests for cdef_classes.rst. Part 4.
parents
36dfbbca
01f48e9e
Changes
2
Show 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 @
1310d1eb
# 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 @
1310d1eb
...
...
@@ -95,26 +95,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