Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Evan Edmond
fslpy
Commits
bef65e56
Commit
bef65e56
authored
4 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
RF: Change re-entrancy logic of disabled ctx manager so that, if
parent
750e46d8
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fsl/utils/assertions.py
+11
-7
11 additions, 7 deletions
fsl/utils/assertions.py
with
11 additions
and
7 deletions
fsl/utils/assertions.py
+
11
−
7
View file @
bef65e56
...
@@ -33,9 +33,8 @@ import fsl.utils.ensure as ensure
...
@@ -33,9 +33,8 @@ import fsl.utils.ensure as ensure
import
fsl.data.melodicanalysis
as
fslma
import
fsl.data.melodicanalysis
as
fslma
_DISABLE_ASSERTIONS
=
False
_DISABLE_ASSERTIONS
=
0
"""
"""
Semaphore used by the :func:`disabled` context manager.
"""
"""
@contextlib.contextmanager
@contextlib.contextmanager
...
@@ -43,18 +42,23 @@ def disabled(disable=True):
...
@@ -43,18 +42,23 @@ def disabled(disable=True):
"""
Context manager which allows assertion checks to be temporarily
"""
Context manager which allows assertion checks to be temporarily
disabled.
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,
:arg disable: Set to ``True`` (the default) to disable assertions,
or ``False`` to enable them.
or ``False`` to enable them.
"""
"""
global
_DISABLE_ASSERTIONS
global
_DISABLE_ASSERTIONS
oldval
=
_DISABLE_ASSERTIONS
if
disable
:
_DISABLE_ASSERTIONS
=
disable
_DISABLE_ASSERTIONS
+
=
1
try
:
try
:
yield
yield
finally
:
finally
:
_DISABLE_ASSERTIONS
=
oldval
if
disable
:
_DISABLE_ASSERTIONS
-=
1
def
_canDisable
(
func
):
def
_canDisable
(
func
):
...
@@ -62,7 +66,7 @@ def _canDisable(func):
...
@@ -62,7 +66,7 @@ def _canDisable(func):
via the :func:`disabled` context manager.
via the :func:`disabled` context manager.
"""
"""
def
wrapper
(
*
args
,
**
kwargs
):
def
wrapper
(
*
args
,
**
kwargs
):
if
not
_DISABLE_ASSERTIONS
:
if
_DISABLE_ASSERTIONS
==
0
:
return
func
(
*
args
,
**
kwargs
)
return
func
(
*
args
,
**
kwargs
)
return
wrapper
return
wrapper
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment