@@ -122,23 +122,51 @@ class Cifti2MetaData(CaretMetaData):
122122 ----------
123123 data : list of (name, value) tuples
124124 """
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()
134+ <Cifti2MetaData {}>
135+ >>> Cifti2MetaData([("key", "val")])
136+ <Cifti2MetaData {'key': 'val'}>
137+ >>> Cifti2MetaData(key="val")
138+ <Cifti2MetaData {'key': 'val'}>
139+ >>> with pytest.warns(FutureWarning):
140+ ... Cifti2MetaData(None)
141+ <Cifti2MetaData {}>
142+ >>> with pytest.warns(FutureWarning):
143+ ... Cifti2MetaData(metadata=None)
144+ <Cifti2MetaData {}>
145+ >>> with pytest.warns(FutureWarning):
146+ ... Cifti2MetaData(metadata={'key': 'val'})
147+ <Cifti2MetaData {'key': 'val'}>
148+
149+ Note that "metadata" could be a valid key:
150+
151+ >>> Cifti2MetaData(metadata='val')
152+ <Cifti2MetaData {'metadata': 'val'}>
153+ """
126154 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 "
130157 "no longer accept the ``metadata`` keyword argument in "
131158 "NiBabel 6.0. See ``pydoc dict`` for initialization options." ,
132- FutureWarning , stacklevel = 2 )
159+ FutureWarning , stacklevel = 3 )
160+ md = kwargs .pop ("metadata" )
133161 if md is not None :
134162 args = (md ,)
135163 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 "
137165 "accept the positional argument ``None`` in NiBabel 6.0. "
138166 "See ``pydoc dict`` for initialization options." ,
139- FutureWarning , stacklevel = 2 )
167+ FutureWarning , stacklevel = 3 )
140168 args = ()
141- super (). __init__ ( * args , ** kwargs )
169+ return args , kwargs
142170
143171 @property
144172 def data (self ):
0 commit comments