Skip to content

[REF] Deprecate kw_only_meth/func decorators #848

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

Merged
merged 3 commits into from
Dec 19, 2019
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
4 changes: 1 addition & 3 deletions nibabel/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
from .fileholders import copy_file_map
from .batteryrunners import Report
from .arrayproxy import ArrayProxy
from .keywordonly import kw_only_meth

# Sub-parts of standard analyze header from
# Mayo dbh.h file
Expand Down Expand Up @@ -933,8 +932,7 @@ def set_data_dtype(self, dtype):
self._header.set_data_dtype(dtype)

@classmethod
@kw_only_meth(1)
def from_file_map(klass, file_map, mmap=True, keep_file_open=None):
def from_file_map(klass, file_map, *, mmap=True, keep_file_open=None):
''' Class method to create image from mapping in ``file_map``

.. deprecated:: 2.4.1
Expand Down
4 changes: 1 addition & 3 deletions nibabel/arrayproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
from .deprecated import deprecate_with_version
from .volumeutils import array_from_file, apply_read_scaling
from .fileslice import fileslice, canonical_slicers
from .keywordonly import kw_only_meth
from . import openers


Expand Down Expand Up @@ -96,8 +95,7 @@ class ArrayProxy(object):
order = 'F'
_header = None

@kw_only_meth(2)
def __init__(self, file_like, spec, mmap=True, keep_file_open=None):
def __init__(self, file_like, spec, *, mmap=True, keep_file_open=None):
"""Initialize array proxy instance

.. deprecated:: 2.4.1
Expand Down
7 changes: 2 additions & 5 deletions nibabel/brikhead.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

from .arrayproxy import ArrayProxy
from .fileslice import strided_scalar
from .keywordonly import kw_only_meth
from .spatialimages import (
SpatialImage,
SpatialHeader,
Expand Down Expand Up @@ -220,8 +219,7 @@ class AFNIArrayProxy(ArrayProxy):
None
"""

@kw_only_meth(2)
def __init__(self, file_like, header, mmap=True, keep_file_open=None):
def __init__(self, file_like, header, *, mmap=True, keep_file_open=None):
"""
Initialize AFNI array proxy

Expand Down Expand Up @@ -504,8 +502,7 @@ class AFNIImage(SpatialImage):
ImageArrayProxy = AFNIArrayProxy

@classmethod
@kw_only_meth(1)
def from_file_map(klass, file_map, mmap=True, keep_file_open=None):
def from_file_map(klass, file_map, *, mmap=True, keep_file_open=None):
"""
Creates an AFNIImage instance from `file_map`

Expand Down
4 changes: 1 addition & 3 deletions nibabel/cifti2/cifti2.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from ..dataobj_images import DataobjImage
from ..nifti2 import Nifti2Image, Nifti2Header
from ..arrayproxy import reshape_dataobj
from ..keywordonly import kw_only_meth
from warnings import warn


Expand Down Expand Up @@ -1389,8 +1388,7 @@ def nifti_header(self):
return self._nifti_header

@classmethod
@kw_only_meth(1)
def from_file_map(klass, file_map, mmap=True, keep_file_open=None):
def from_file_map(klass, file_map, *, mmap=True, keep_file_open=None):
""" Load a CIFTI-2 image from a file_map

Parameters
Expand Down
7 changes: 2 additions & 5 deletions nibabel/dataobj_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

from .arrayproxy import is_proxy
from .filebasedimages import FileBasedImage
from .keywordonly import kw_only_meth
from .deprecated import deprecate_with_version


Expand Down Expand Up @@ -420,8 +419,7 @@ def get_shape(self):
return self.shape

@classmethod
@kw_only_meth(1)
def from_file_map(klass, file_map, mmap=True, keep_file_open=None):
def from_file_map(klass, file_map, *, mmap=True, keep_file_open=None):
''' Class method to create image from mapping in ``file_map``

.. deprecated:: 2.4.1
Expand Down Expand Up @@ -458,8 +456,7 @@ def from_file_map(klass, file_map, mmap=True, keep_file_open=None):
raise NotImplementedError

@classmethod
@kw_only_meth(1)
def from_filename(klass, filename, mmap=True, keep_file_open=None):
def from_filename(klass, filename, *, mmap=True, keep_file_open=None):
'''Class method to create image from filename `filename`

.. deprecated:: 2.4.1
Expand Down
4 changes: 1 addition & 3 deletions nibabel/ecat.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
from .arraywriters import make_array_writer
from .wrapstruct import WrapStruct
from .fileslice import canonical_slicers, predict_shape, slice2outax
from .keywordonly import kw_only_meth
from .deprecated import deprecate_with_version

BLOCK_SIZE = 512
Expand Down Expand Up @@ -901,8 +900,7 @@ def _get_fileholders(file_map):
return file_map['header'], file_map['image']

@classmethod
@kw_only_meth(1)
def from_file_map(klass, file_map, mmap=True, keep_file_open=None):
def from_file_map(klass, file_map, *, mmap=True, keep_file_open=None):
"""class method to create image from mapping
specified in file_map
"""
Expand Down
4 changes: 1 addition & 3 deletions nibabel/freesurfer/mghformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from ..spatialimages import HeaderDataError, SpatialImage
from ..fileholders import FileHolder
from ..arrayproxy import ArrayProxy, reshape_dataobj
from ..keywordonly import kw_only_meth
from ..openers import ImageOpener
from ..batteryrunners import BatteryRunner, Report
from ..wrapstruct import LabeledWrapStruct
Expand Down Expand Up @@ -537,8 +536,7 @@ def filespec_to_file_map(klass, filespec):
return super(MGHImage, klass).filespec_to_file_map(filespec)

@classmethod
@kw_only_meth(1)
def from_file_map(klass, file_map, mmap=True, keep_file_open=None):
def from_file_map(klass, file_map, *, mmap=True, keep_file_open=None):
''' Class method to create image from mapping in ``file_map``

.. deprecated:: 2.4.1
Expand Down
7 changes: 7 additions & 0 deletions nibabel/keywordonly.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
"""

from functools import wraps
import warnings

warnings.warn("We will remove this module from nibabel 5.0. "
"Please use the built-in Python `*` argument to ensure "
"keyword-only parameters (see PEP 3102).",
DeprecationWarning,
stacklevel=2)


def kw_only_func(n):
Expand Down
4 changes: 1 addition & 3 deletions nibabel/minc1.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from .spatialimages import SpatialHeader, SpatialImage
from .fileslice import canonical_slicers

from .keywordonly import kw_only_meth
from .deprecated import deprecate_with_version

_dt_dict = {
Expand Down Expand Up @@ -340,8 +339,7 @@ class Minc1Image(SpatialImage):
ImageArrayProxy = MincImageArrayProxy

@classmethod
@kw_only_meth(1)
def from_file_map(klass, file_map, mmap=True, keep_file_open=None):
def from_file_map(klass, file_map, *, mmap=True, keep_file_open=None):
# Note that mmap and keep_file_open are included for proper
with file_map['image'].get_prepare_fileobj() as fobj:
minc_file = Minc1File(netcdf_file(fobj))
Expand Down
4 changes: 1 addition & 3 deletions nibabel/minc2.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"""
import numpy as np

from .keywordonly import kw_only_meth
from ._h5py_compat import h5py

from .minc1 import Minc1File, MincHeader, Minc1Image, MincError
Expand Down Expand Up @@ -158,8 +157,7 @@ class Minc2Image(Minc1Image):
header_class = Minc2Header

@classmethod
@kw_only_meth(1)
def from_file_map(klass, file_map, mmap=True, keep_file_open=None):
def from_file_map(klass, file_map, *, mmap=True, keep_file_open=None):
holder = file_map['image']
if holder.filename is None:
raise MincError('MINC2 needs filename for load')
Expand Down
10 changes: 3 additions & 7 deletions nibabel/parrec.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@
from locale import getpreferredencoding
from collections import OrderedDict

from .keywordonly import kw_only_meth
from .spatialimages import SpatialHeader, SpatialImage
from .eulerangles import euler2mat
from .volumeutils import Recoder, array_from_file
Expand Down Expand Up @@ -584,8 +583,7 @@ def exts2pars(exts_source):

class PARRECArrayProxy(object):

@kw_only_meth(2)
def __init__(self, file_like, header, mmap=True, scaling='dv'):
def __init__(self, file_like, header, *, mmap=True, scaling='dv'):
""" Initialize PARREC array proxy

Parameters
Expand Down Expand Up @@ -1277,8 +1275,7 @@ class PARRECImage(SpatialImage):
ImageArrayProxy = PARRECArrayProxy

@classmethod
@kw_only_meth(1)
def from_file_map(klass, file_map, mmap=True, permit_truncated=False,
def from_file_map(klass, file_map, *, mmap=True, permit_truncated=False,
scaling='dv', strict_sort=False):
""" Create PARREC image from file map `file_map`

Expand Down Expand Up @@ -1318,8 +1315,7 @@ def from_file_map(klass, file_map, mmap=True, permit_truncated=False,
file_map=file_map)

@classmethod
@kw_only_meth(1)
def from_filename(klass, filename, mmap=True, permit_truncated=False,
def from_filename(klass, filename, *, mmap=True, permit_truncated=False,
scaling='dv', strict_sort=False):
""" Create PARREC image from filename `filename`

Expand Down
4 changes: 1 addition & 3 deletions nibabel/spm99analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

from .batteryrunners import Report
from . import analyze # module import
from .keywordonly import kw_only_meth
from .optpkg import optional_package
have_scipy = optional_package('scipy')[1]

Expand Down Expand Up @@ -244,8 +243,7 @@ class Spm99AnalyzeImage(analyze.AnalyzeImage):
rw = have_scipy

@classmethod
@kw_only_meth(1)
def from_file_map(klass, file_map, mmap=True, keep_file_open=None):
def from_file_map(klass, file_map, *, mmap=True, keep_file_open=None):
''' Class method to create image from mapping in ``file_map``

.. deprecated:: 2.4.1
Expand Down
1 change: 1 addition & 0 deletions nibabel/tests/test_removalschedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from ..testing import assert_raises, assert_false

MODULE_SCHEDULE = [
('5.0.0', ['nibabel.keywordonly']),
('4.0.0', ['nibabel.trackvis']),
('3.0.0', ['nibabel.minc', 'nibabel.checkwarns']),
# Verify that the test will be quiet if the schedule outlives the modules
Expand Down