Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MRG, BUG: Force keywords for verbose in short sigs #8350

Merged
merged 2 commits into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/changes/latest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Bugs

- Fix bug with :func:`mne.add_reference_channels` when :func:`mne.io.Raw.reorder_channels` or related methods are used afterward by `Eric Larson`_ (:gh:`8303`)

- Fix bug where the ``verbose`` arguments to :meth:`mne.Evoked.apply_baseline` and :meth:`mne.Epochs.apply_baseline` were not keyword-only by `Eric Larson`_ (:gh:`8349`)

- ``ICA.max_pca_components`` will not be altered by calling `~mne.preprocessing.ICA.fit` anymore. Instead, the new attribute ``ICA.max_pca_components_`` will be set, by `Richard Höchenberger`_ (:gh:`8321`)

- Fix bug that `~mne.viz.plot_ica_overlay` would sometimes not create red traces, by `Richard Höchenberger`_ (:gh:`8341`)
Expand Down
2 changes: 1 addition & 1 deletion mne/epochs.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ def decimate(self, decim, offset=0, verbose=None):
return self

@verbose
def apply_baseline(self, baseline=(None, 0), verbose=None):
def apply_baseline(self, baseline=(None, 0), *, verbose=None):
"""Baseline correct epochs.

Parameters
Expand Down
2 changes: 1 addition & 1 deletion mne/evoked.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def data(self, data):
self._data = data

@verbose
def apply_baseline(self, baseline=(None, 0), verbose=None):
def apply_baseline(self, baseline=(None, 0), *, verbose=None):
"""Baseline correct evoked data.

Parameters
Expand Down
53 changes: 28 additions & 25 deletions mne/utils/_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,33 +97,35 @@ def verbose(function):
# Anything using verbose should either have `verbose=None` in the signature
# or have a `self.verbose` attribute (if in a method). This code path
# will raise an error if neither is the case.
wrap_src = """\
try:
verbose
except UnboundLocalError:
body = """\
def %(name)s(%(signature)s):\n
try:
verbose = self.verbose
except NameError:
raise RuntimeError('Function %%s does not accept verbose parameter'
%% (_function_,))
except AttributeError:
raise RuntimeError('Method %%s class does not have self.verbose'
%% (_function_,))
if verbose is None:
try:
verbose = self.verbose
except (NameError, AttributeError):
pass
if verbose is not None:
with _use_log_level_(verbose):
return _function_(%(signature)s)
return _function_(%(signature)s)"""
verbose
except UnboundLocalError:
try:
verbose = self.verbose
except NameError:
raise RuntimeError('Function %%s does not accept verbose parameter'
%% (_function_,))
except AttributeError:
raise RuntimeError('Method %%s class does not have self.verbose'
%% (_function_,))
else:
if verbose is None:
try:
verbose = self.verbose
except (NameError, AttributeError):
pass
if verbose is not None:
with _use_log_level_(verbose):
return _function_(%(shortsignature)s)
else:
return _function_(%(shortsignature)s)"""
evaldict = dict(
_use_log_level_=use_log_level, _function_=function)
return FunctionMaker.create(
function, wrap_src, evaldict,
__wrapped__=function, __qualname__=function.__qualname__,
module=function.__module__)
fm = FunctionMaker(function, None, None, None, None, function.__module__)
attrs = dict(__wrapped__=function, __qualname__=function.__qualname__)
return fm.make(body, evaldict, addsource=True, **attrs)


class use_log_level(object):
Expand Down Expand Up @@ -175,7 +177,8 @@ def set_log_level(verbose=None, return_old_level=False, add_frames=None):
The old level. Only returned if ``return_old_level`` is True.
"""
from .config import get_config
from .check import _check_option
from .check import _check_option, _validate_type
_validate_type(verbose, (bool, str, int, None), 'verbose')
if verbose is None:
verbose = get_config('MNE_LOGGING_LEVEL', 'INFO')
elif isinstance(verbose, bool):
Expand Down
3 changes: 2 additions & 1 deletion mne/utils/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
docdict['verbose'] = """
verbose : bool, str, int, or None
If not None, override default verbose level (see :func:`mne.verbose`
and :ref:`Logging documentation <tut_logging>` for more)."""
and :ref:`Logging documentation <tut_logging>` for more).
If used, it should be passed as a keyword-argument only."""
docdict['verbose_meth'] = (docdict['verbose'] + ' Defaults to self.verbose.')

# Preload
Expand Down
2 changes: 1 addition & 1 deletion mne/utils/tests/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_doc_filling(obj):
doc = obj.__doc__
assert 'verbose : ' in doc
if obj is add_channels_epochs:
assert 'for more). Defaults to True if' in doc
assert 'keyword-argument only. Defaults to True if' in doc


def test_deprecated_alias():
Expand Down