@@ -33,17 +33,17 @@ def _check_annotations(value):
3333 """
3434 if isinstance (value , np .ndarray ):
3535 if not issubclass (value .dtype .type , ALLOWED_ANNOTATION_TYPES ):
36- raise ValueError ("Invalid annotation. NumPy arrays with dtype %s "
37- "are not allowed" % value . dtype . type )
36+ raise ValueError (f "Invalid annotation. NumPy arrays with dtype { value . dtype . type } "
37+ f "are not allowed" )
3838 elif isinstance (value , dict ):
3939 for element in value .values ():
4040 _check_annotations (element )
4141 elif isinstance (value , (list , tuple )):
4242 for element in value :
4343 _check_annotations (element )
4444 elif not isinstance (value , ALLOWED_ANNOTATION_TYPES ):
45- raise ValueError ("Invalid annotation. Annotations of type %s are not"
46- "allowed" % type ( value ) )
45+ raise ValueError (f "Invalid annotation. Annotations of type { type ( value ) } are not"
46+ f "allowed" )
4747
4848
4949def merge_annotation (a , b ):
@@ -58,8 +58,7 @@ def merge_annotation(a, b):
5858 For strings: concatenate with ';'
5959 Otherwise: fail if the annotations are not equal
6060 """
61- assert type (a ) == type (b ), 'type({}) {} != type({}) {}' .format (a , type (a ),
62- b , type (b ))
61+ assert type (a ) == type (b ), f'type({ a } )) { type (a )} != type({ b } ) { type (b )} '
6362 if isinstance (a , dict ):
6463 return merge_annotations (a , b )
6564 elif isinstance (a , np .ndarray ): # concatenate b to a
@@ -72,7 +71,7 @@ def merge_annotation(a, b):
7271 else :
7372 return a + ";" + b
7473 else :
75- assert a == b , '{ } != {}' . format ( a , b )
74+ assert a == b , f' { a } != { b } '
7675 return a
7776
7877
@@ -100,7 +99,7 @@ def merge_annotations(A, *Bs):
10099 # exc.args += ('key %s' % name,)
101100 # raise
102101 merged [name ] = "MERGE CONFLICT" # temporary hack
103- logger .debug ("Merging annotations: A=%s Bs=%s merged=%s" , A , Bs , merged )
102+ logger .debug (f "Merging annotations: A={ A } Bs={ Bs } merged={ merged } " )
104103 return merged
105104
106105
@@ -122,8 +121,7 @@ def intersect_annotations(A, B):
122121
123122 for key in set (A .keys ()) & set (B .keys ()):
124123 v1 , v2 = A [key ], B [key ]
125- assert type (v1 ) == type (v2 ), 'type({}) {} != type({}) {}' .format (v1 , type (v1 ),
126- v2 , type (v2 ))
124+ assert type (v1 ) == type (v2 ), f'type({ v1 } ) { type (v1 )} != type({ v2 } ) { type (v2 )} '
127125 if isinstance (v1 , dict ) and v1 == v2 :
128126 result [key ] = deepcopy (v1 )
129127 elif isinstance (v1 , str ) and v1 == v2 :
@@ -299,7 +297,7 @@ def _repr_pretty_attrs_(self, pp, cycle):
299297 else :
300298 pp .breakable ()
301299 with pp .group (indent = 1 ):
302- pp .text ("{ }: ". format ( key ) )
300+ pp .text (f" { key } : " )
303301 pp .pretty (value )
304302
305303 def _repr_pretty_ (self , pp , cycle ):
@@ -366,8 +364,8 @@ def set_parent(self, obj):
366364 according to the type of "obj"
367365 """
368366 if obj .__class__ .__name__ not in self ._parent_objects :
369- raise TypeError ("{ } can only have parents of type {}, not {}" . format (
370- self . __class__ . __name__ , self ._parent_objects , obj .__class__ .__name__ ))
367+ raise TypeError (( f" { self . __class__ . __name__ } can only have parents of "
368+ f"type { self ._parwents_objects } , not { obj .__class__ .__name__ } " ))
371369 loc = self ._parent_objects .index (obj .__class__ .__name__ )
372370 parent_attr = self ._parent_attrs [loc ]
373371 setattr (self , parent_attr , obj )
0 commit comments