Skip to content

Commit 6425c2a

Browse files
authored
Merge pull request #848 from rmarkello/ref/kwonly
[REF] Deprecate kw_only_meth/func decorators
2 parents 4f366d3 + e69ec32 commit 6425c2a

13 files changed

+23
-41
lines changed

nibabel/analyze.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@
9595
from .fileholders import copy_file_map
9696
from .batteryrunners import Report
9797
from .arrayproxy import ArrayProxy
98-
from .keywordonly import kw_only_meth
9998

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

935934
@classmethod
936-
@kw_only_meth(1)
937-
def from_file_map(klass, file_map, mmap=True, keep_file_open=None):
935+
def from_file_map(klass, file_map, *, mmap=True, keep_file_open=None):
938936
''' Class method to create image from mapping in ``file_map``
939937
940938
.. deprecated:: 2.4.1

nibabel/arrayproxy.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
from .deprecated import deprecate_with_version
3434
from .volumeutils import array_from_file, apply_read_scaling
3535
from .fileslice import fileslice, canonical_slicers
36-
from .keywordonly import kw_only_meth
3736
from . import openers
3837

3938

@@ -93,8 +92,7 @@ class ArrayProxy(object):
9392
order = 'F'
9493
_header = None
9594

96-
@kw_only_meth(2)
97-
def __init__(self, file_like, spec, mmap=True, keep_file_open=None):
95+
def __init__(self, file_like, spec, *, mmap=True, keep_file_open=None):
9896
"""Initialize array proxy instance
9997
10098
.. deprecated:: 2.4.1

nibabel/brikhead.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
from .arrayproxy import ArrayProxy
3838
from .fileslice import strided_scalar
39-
from .keywordonly import kw_only_meth
4039
from .spatialimages import (
4140
SpatialImage,
4241
SpatialHeader,
@@ -220,8 +219,7 @@ class AFNIArrayProxy(ArrayProxy):
220219
None
221220
"""
222221

223-
@kw_only_meth(2)
224-
def __init__(self, file_like, header, mmap=True, keep_file_open=None):
222+
def __init__(self, file_like, header, *, mmap=True, keep_file_open=None):
225223
"""
226224
Initialize AFNI array proxy
227225
@@ -504,8 +502,7 @@ class AFNIImage(SpatialImage):
504502
ImageArrayProxy = AFNIArrayProxy
505503

506504
@classmethod
507-
@kw_only_meth(1)
508-
def from_file_map(klass, file_map, mmap=True, keep_file_open=None):
505+
def from_file_map(klass, file_map, *, mmap=True, keep_file_open=None):
509506
"""
510507
Creates an AFNIImage instance from `file_map`
511508

nibabel/cifti2/cifti2.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from ..dataobj_images import DataobjImage
2525
from ..nifti2 import Nifti2Image, Nifti2Header
2626
from ..arrayproxy import reshape_dataobj
27-
from ..keywordonly import kw_only_meth
2827
from warnings import warn
2928

3029

@@ -1389,8 +1388,7 @@ def nifti_header(self):
13891388
return self._nifti_header
13901389

13911390
@classmethod
1392-
@kw_only_meth(1)
1393-
def from_file_map(klass, file_map, mmap=True, keep_file_open=None):
1391+
def from_file_map(klass, file_map, *, mmap=True, keep_file_open=None):
13941392
""" Load a CIFTI-2 image from a file_map
13951393
13961394
Parameters

nibabel/dataobj_images.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import numpy as np
1212

1313
from .filebasedimages import FileBasedImage
14-
from .keywordonly import kw_only_meth
1514
from .deprecated import deprecate_with_version
1615

1716

@@ -415,8 +414,7 @@ def get_shape(self):
415414
return self.shape
416415

417416
@classmethod
418-
@kw_only_meth(1)
419-
def from_file_map(klass, file_map, mmap=True, keep_file_open=None):
417+
def from_file_map(klass, file_map, *, mmap=True, keep_file_open=None):
420418
''' Class method to create image from mapping in ``file_map``
421419
422420
.. deprecated:: 2.4.1
@@ -453,8 +451,7 @@ def from_file_map(klass, file_map, mmap=True, keep_file_open=None):
453451
raise NotImplementedError
454452

455453
@classmethod
456-
@kw_only_meth(1)
457-
def from_filename(klass, filename, mmap=True, keep_file_open=None):
454+
def from_filename(klass, filename, *, mmap=True, keep_file_open=None):
458455
'''Class method to create image from filename `filename`
459456
460457
.. deprecated:: 2.4.1

nibabel/ecat.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
from .arraywriters import make_array_writer
5555
from .wrapstruct import WrapStruct
5656
from .fileslice import canonical_slicers, predict_shape, slice2outax
57-
from .keywordonly import kw_only_meth
5857
from .deprecated import deprecate_with_version
5958

6059
BLOCK_SIZE = 512
@@ -888,8 +887,7 @@ def _get_fileholders(file_map):
888887
return file_map['header'], file_map['image']
889888

890889
@classmethod
891-
@kw_only_meth(1)
892-
def from_file_map(klass, file_map, mmap=True, keep_file_open=None):
890+
def from_file_map(klass, file_map, *, mmap=True, keep_file_open=None):
893891
"""class method to create image from mapping
894892
specified in file_map
895893
"""

nibabel/freesurfer/mghformat.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from ..spatialimages import HeaderDataError, SpatialImage
2222
from ..fileholders import FileHolder
2323
from ..arrayproxy import ArrayProxy, reshape_dataobj
24-
from ..keywordonly import kw_only_meth
2524
from ..openers import ImageOpener
2625
from ..batteryrunners import BatteryRunner, Report
2726
from ..wrapstruct import LabeledWrapStruct
@@ -537,8 +536,7 @@ def filespec_to_file_map(klass, filespec):
537536
return super(MGHImage, klass).filespec_to_file_map(filespec)
538537

539538
@classmethod
540-
@kw_only_meth(1)
541-
def from_file_map(klass, file_map, mmap=True, keep_file_open=None):
539+
def from_file_map(klass, file_map, *, mmap=True, keep_file_open=None):
542540
''' Class method to create image from mapping in ``file_map``
543541
544542
.. deprecated:: 2.4.1

nibabel/keywordonly.py

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
"""
33

44
from functools import wraps
5+
import warnings
6+
7+
warnings.warn("We will remove this module from nibabel 5.0. "
8+
"Please use the built-in Python `*` argument to ensure "
9+
"keyword-only parameters (see PEP 3102).",
10+
DeprecationWarning,
11+
stacklevel=2)
512

613

714
def kw_only_func(n):

nibabel/minc1.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from .spatialimages import SpatialHeader, SpatialImage
1818
from .fileslice import canonical_slicers
1919

20-
from .keywordonly import kw_only_meth
2120
from .deprecated import deprecate_with_version
2221

2322
_dt_dict = {
@@ -327,8 +326,7 @@ class Minc1Image(SpatialImage):
327326
ImageArrayProxy = MincImageArrayProxy
328327

329328
@classmethod
330-
@kw_only_meth(1)
331-
def from_file_map(klass, file_map, mmap=True, keep_file_open=None):
329+
def from_file_map(klass, file_map, *, mmap=True, keep_file_open=None):
332330
# Note that mmap and keep_file_open are included for proper
333331
with file_map['image'].get_prepare_fileobj() as fobj:
334332
minc_file = Minc1File(netcdf_file(fobj))

nibabel/minc2.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"""
2828
import numpy as np
2929

30-
from .keywordonly import kw_only_meth
3130
from ._h5py_compat import h5py
3231

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

160159
@classmethod
161-
@kw_only_meth(1)
162-
def from_file_map(klass, file_map, mmap=True, keep_file_open=None):
160+
def from_file_map(klass, file_map, *, mmap=True, keep_file_open=None):
163161
holder = file_map['image']
164162
if holder.filename is None:
165163
raise MincError('MINC2 needs filename for load')

nibabel/parrec.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@
130130
from locale import getpreferredencoding
131131
from collections import OrderedDict
132132

133-
from .keywordonly import kw_only_meth
134133
from .spatialimages import SpatialHeader, SpatialImage
135134
from .eulerangles import euler2mat
136135
from .volumeutils import Recoder, array_from_file
@@ -584,8 +583,7 @@ def exts2pars(exts_source):
584583

585584
class PARRECArrayProxy(object):
586585

587-
@kw_only_meth(2)
588-
def __init__(self, file_like, header, mmap=True, scaling='dv'):
586+
def __init__(self, file_like, header, *, mmap=True, scaling='dv'):
589587
""" Initialize PARREC array proxy
590588
591589
Parameters
@@ -1273,8 +1271,7 @@ class PARRECImage(SpatialImage):
12731271
ImageArrayProxy = PARRECArrayProxy
12741272

12751273
@classmethod
1276-
@kw_only_meth(1)
1277-
def from_file_map(klass, file_map, mmap=True, permit_truncated=False,
1274+
def from_file_map(klass, file_map, *, mmap=True, permit_truncated=False,
12781275
scaling='dv', strict_sort=False):
12791276
""" Create PARREC image from file map `file_map`
12801277
@@ -1314,8 +1311,7 @@ def from_file_map(klass, file_map, mmap=True, permit_truncated=False,
13141311
file_map=file_map)
13151312

13161313
@classmethod
1317-
@kw_only_meth(1)
1318-
def from_filename(klass, filename, mmap=True, permit_truncated=False,
1314+
def from_filename(klass, filename, *, mmap=True, permit_truncated=False,
13191315
scaling='dv', strict_sort=False):
13201316
""" Create PARREC image from filename `filename`
13211317

nibabel/spm99analyze.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
from .batteryrunners import Report
1818
from . import analyze # module import
19-
from .keywordonly import kw_only_meth
2019
from .optpkg import optional_package
2120
have_scipy = optional_package('scipy')[1]
2221

@@ -244,8 +243,7 @@ class Spm99AnalyzeImage(analyze.AnalyzeImage):
244243
rw = have_scipy
245244

246245
@classmethod
247-
@kw_only_meth(1)
248-
def from_file_map(klass, file_map, mmap=True, keep_file_open=None):
246+
def from_file_map(klass, file_map, *, mmap=True, keep_file_open=None):
249247
''' Class method to create image from mapping in ``file_map``
250248
251249
.. deprecated:: 2.4.1

nibabel/tests/test_removalschedule.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from ..testing import assert_raises, assert_false
33

44
MODULE_SCHEDULE = [
5+
('5.0.0', ['nibabel.keywordonly']),
56
('4.0.0', ['nibabel.trackvis']),
67
('3.0.0', ['nibabel.minc', 'nibabel.checkwarns']),
78
# Verify that the test will be quiet if the schedule outlives the modules

0 commit comments

Comments
 (0)