2121
2222__all__ = ["TaskMetadata" ]
2323
24- import numbers
2524import itertools
25+ import numbers
2626import warnings
2727from collections .abc import Sequence
28- from deprecated . sphinx import deprecated
28+ from typing import Any , Collection , Dict , List , Mapping , Protocol , Union
2929
30- from typing import Dict , List , Union , Any , Mapping , Protocol , Collection
31- from pydantic import BaseModel , StrictInt , StrictFloat , StrictBool , StrictStr , Field
30+ from deprecated . sphinx import deprecated
31+ from pydantic import BaseModel , Field , StrictBool , StrictFloat , StrictInt , StrictStr
3232
3333_DEPRECATION_REASON = "Will be removed after v25."
3434_DEPRECATION_VERSION = "v24"
@@ -73,8 +73,9 @@ class TaskMetadata(BaseModel):
7373 """
7474
7575 scalars : Dict [str , Union [StrictFloat , StrictInt , StrictBool , StrictStr ]] = Field (default_factory = dict )
76- arrays : Dict [str , Union [List [StrictFloat ], List [StrictInt ], List [StrictBool ],
77- List [StrictStr ]]] = Field (default_factory = dict )
76+ arrays : Dict [str , Union [List [StrictFloat ], List [StrictInt ], List [StrictBool ], List [StrictStr ]]] = Field (
77+ default_factory = dict
78+ )
7879 metadata : Dict [str , "TaskMetadata" ] = Field (default_factory = dict )
7980
8081 @classmethod
@@ -175,8 +176,11 @@ def add(self, name, value):
175176
176177 self .metadata [key0 ].add ("." .join (keys ), value )
177178
178- @deprecated (reason = "Cast the return value to float explicitly. " + _DEPRECATION_REASON ,
179- version = _DEPRECATION_VERSION , category = FutureWarning )
179+ @deprecated (
180+ reason = "Cast the return value to float explicitly. " + _DEPRECATION_REASON ,
181+ version = _DEPRECATION_VERSION ,
182+ category = FutureWarning ,
183+ )
180184 def getAsDouble (self , key ):
181185 """Return the value cast to a `float`.
182186
@@ -288,7 +292,7 @@ def names(self, topLevelOnly: bool = True):
288292 for k , v in self .items ():
289293 names .add (k ) # Always include the current level
290294 if isinstance (v , TaskMetadata ):
291- names .update ({k + '.' + item for item in v .names (topLevelOnly = topLevelOnly )})
295+ names .update ({k + "." + item for item in v .names (topLevelOnly = topLevelOnly )})
292296 return names
293297
294298 def paramNames (self , topLevelOnly ):
@@ -318,14 +322,20 @@ def paramNames(self, topLevelOnly):
318322 paramNames .add (k )
319323 return paramNames
320324
321- @deprecated (reason = "Use standard assignment syntax. " + _DEPRECATION_REASON ,
322- version = _DEPRECATION_VERSION , category = FutureWarning )
325+ @deprecated (
326+ reason = "Use standard assignment syntax. " + _DEPRECATION_REASON ,
327+ version = _DEPRECATION_VERSION ,
328+ category = FutureWarning ,
329+ )
323330 def set (self , key , item ):
324331 """Set the value of the supplied key."""
325332 self .__setitem__ (key , item )
326333
327- @deprecated (reason = "Use standard del dict syntax. " + _DEPRECATION_REASON ,
328- version = _DEPRECATION_VERSION , category = FutureWarning )
334+ @deprecated (
335+ reason = "Use standard del dict syntax. " + _DEPRECATION_REASON ,
336+ version = _DEPRECATION_VERSION ,
337+ category = FutureWarning ,
338+ )
329339 def remove (self , key ):
330340 """Remove the item without raising if absent."""
331341 try :
@@ -354,7 +364,7 @@ def _getKeys(key):
354364 Raised if the key is not a string.
355365 """
356366 try :
357- keys = key .split ('.' )
367+ keys = key .split ("." )
358368 except Exception :
359369 raise KeyError (f"Invalid key '{ key } ': only string keys are allowed" ) from None
360370 return keys
@@ -518,8 +528,10 @@ def _validate_value(self, value):
518528 type0 = type (value [0 ])
519529 for i in value :
520530 if type (i ) != type0 :
521- raise ValueError ("Type mismatch in supplied list. TaskMetadata requires all"
522- f" elements have same type but see { type (i )} and { type0 } ." )
531+ raise ValueError (
532+ "Type mismatch in supplied list. TaskMetadata requires all"
533+ f" elements have same type but see { type (i )} and { type0 } ."
534+ )
523535
524536 if type0 not in _ALLOWED_PRIMITIVE_TYPES :
525537 # Must check to see if we got numpy floats or something.
@@ -528,8 +540,10 @@ def _validate_value(self, value):
528540 elif isinstance (value [0 ], numbers .Real ):
529541 type_cast = float
530542 else :
531- raise ValueError (f"Supplied list has element of type '{ type0 } '. "
532- "TaskMetadata can only accept primitive types in lists." )
543+ raise ValueError (
544+ f"Supplied list has element of type '{ type0 } '. "
545+ "TaskMetadata can only accept primitive types in lists."
546+ )
533547
534548 value = [type_cast (v ) for v in value ]
535549
0 commit comments