Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
FSL
fslpy
Commits
bef65e56
Commit
bef65e56
authored
Oct 20, 2020
by
Paul McCarthy
🚵
Browse files
RF: Change re-entrancy logic of disabled ctx manager so that, if
parent
750e46d8
Changes
1
Hide whitespace changes
Inline
Side-by-side
fsl/utils/assertions.py
View file @
bef65e56
...
...
@@ -33,9 +33,8 @@ import fsl.utils.ensure as ensure
import
fsl.data.melodicanalysis
as
fslma
_DISABLE_ASSERTIONS
=
False
"""
"""
_DISABLE_ASSERTIONS
=
0
"""Semaphore used by the :func:`disabled` context manager. """
@
contextlib
.
contextmanager
...
...
@@ -43,18 +42,23 @@ def disabled(disable=True):
"""Context manager which allows assertion checks to be temporarily
disabled.
If calls to this function are nested, only one of the calls need to be made
with ``disable=True`` for assertions to be disabled; any other calls which
are part of the call stack which set ``disable=False`` will have no effect.
:arg disable: Set to ``True`` (the default) to disable assertions,
or ``False`` to enable them.
"""
global
_DISABLE_ASSERTIONS
oldval
=
_DISABLE_ASSERTIONS
_DISABLE_ASSERTIONS
=
disable
if
disable
:
_DISABLE_ASSERTIONS
+
=
1
try
:
yield
finally
:
_DISABLE_ASSERTIONS
=
oldval
if
disable
:
_DISABLE_ASSERTIONS
-=
1
def
_canDisable
(
func
):
...
...
@@ -62,7 +66,7 @@ def _canDisable(func):
via the :func:`disabled` context manager.
"""
def
wrapper
(
*
args
,
**
kwargs
):
if
not
_DISABLE_ASSERTIONS
:
if
_DISABLE_ASSERTIONS
==
0
:
return
func
(
*
args
,
**
kwargs
)
return
wrapper
...
...
Write
Preview
Supports
Markdown
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