@@ -122,23 +122,51 @@ class Cifti2MetaData(CaretMetaData):
122
122
----------
123
123
data : list of (name, value) tuples
124
124
"""
125
- def __init__ (self , * args , ** kwargs ):
125
+ @staticmethod
126
+ def _sanitize (args , kwargs ):
127
+ """ Sanitize and warn on deprecated arguments
128
+
129
+ Accept metadata positional/keyword argument that can take
130
+ ``None`` to indicate no initialization.
131
+
132
+ >>> import pytest
133
+ >>> Cifti2MetaData._sanitize((), {})
134
+ ((), {})
135
+ >>> Cifti2MetaData._sanitize(([("key", "val")],), {})
136
+ (([('key', 'val')],), {})
137
+ >>> Cifti2MetaData._sanitize((), {"key": "val"})
138
+ ((), {'key': 'val'})
139
+ >>> with pytest.warns(FutureWarning):
140
+ ... Cifti2MetaData._sanitize((None,), {})
141
+ ((), {})
142
+ >>> with pytest.warns(FutureWarning):
143
+ ... Cifti2MetaData._sanitize((), {'metadata': None})
144
+ ((), {})
145
+ >>> with pytest.warns(FutureWarning):
146
+ ... Cifti2MetaData._sanitize((), {'metadata': {'key': 'val'}})
147
+ (({'key': 'val'},), {})
148
+
149
+ Note that "metadata" could be a valid key:
150
+
151
+ >>> Cifti2MetaData._sanitize((), {'metadata': 'val'})
152
+ ((), {'metadata': 'val'})
153
+ """
126
154
if not args and list (kwargs ) == ["metadata" ]:
127
- md = kwargs .pop ("metadata" )
128
- if not isinstance (md , str ):
129
- warn ("CaretMetaData now has a dict-like interface and will "
155
+ if not isinstance (kwargs ["metadata" ], str ):
156
+ warn ("Cifti2MetaData now has a dict-like interface and will "
130
157
"no longer accept the ``metadata`` keyword argument in "
131
158
"NiBabel 6.0. See ``pydoc dict`` for initialization options." ,
132
- FutureWarning , stacklevel = 2 )
159
+ FutureWarning , stacklevel = 3 )
160
+ md = kwargs .pop ("metadata" )
133
161
if md is not None :
134
162
args = (md ,)
135
163
if args == (None ,):
136
- warn ("CaretMetaData now has a dict-like interface and will no longer "
164
+ warn ("Cifti2MetaData now has a dict-like interface and will no longer "
137
165
"accept the positional argument ``None`` in NiBabel 6.0. "
138
166
"See ``pydoc dict`` for initialization options." ,
139
- FutureWarning , stacklevel = 2 )
167
+ FutureWarning , stacklevel = 3 )
140
168
args = ()
141
- super (). __init__ ( * args , ** kwargs )
169
+ return args , kwargs
142
170
143
171
@property
144
172
def data (self ):
0 commit comments