@@ -33,17 +33,17 @@ def _check_annotations(value):
33
33
"""
34
34
if isinstance (value , np .ndarray ):
35
35
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" )
38
38
elif isinstance (value , dict ):
39
39
for element in value .values ():
40
40
_check_annotations (element )
41
41
elif isinstance (value , (list , tuple )):
42
42
for element in value :
43
43
_check_annotations (element )
44
44
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" )
47
47
48
48
49
49
def merge_annotation (a , b ):
@@ -58,8 +58,7 @@ def merge_annotation(a, b):
58
58
For strings: concatenate with ';'
59
59
Otherwise: fail if the annotations are not equal
60
60
"""
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 )} '
63
62
if isinstance (a , dict ):
64
63
return merge_annotations (a , b )
65
64
elif isinstance (a , np .ndarray ): # concatenate b to a
@@ -72,7 +71,7 @@ def merge_annotation(a, b):
72
71
else :
73
72
return a + ";" + b
74
73
else :
75
- assert a == b , '{ } != {}' . format ( a , b )
74
+ assert a == b , f' { a } != { b } '
76
75
return a
77
76
78
77
@@ -100,7 +99,7 @@ def merge_annotations(A, *Bs):
100
99
# exc.args += ('key %s' % name,)
101
100
# raise
102
101
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 } " )
104
103
return merged
105
104
106
105
@@ -122,8 +121,7 @@ def intersect_annotations(A, B):
122
121
123
122
for key in set (A .keys ()) & set (B .keys ()):
124
123
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 )} '
127
125
if isinstance (v1 , dict ) and v1 == v2 :
128
126
result [key ] = deepcopy (v1 )
129
127
elif isinstance (v1 , str ) and v1 == v2 :
@@ -299,7 +297,7 @@ def _repr_pretty_attrs_(self, pp, cycle):
299
297
else :
300
298
pp .breakable ()
301
299
with pp .group (indent = 1 ):
302
- pp .text ("{ }: ". format ( key ) )
300
+ pp .text (f" { key } : " )
303
301
pp .pretty (value )
304
302
305
303
def _repr_pretty_ (self , pp , cycle ):
@@ -366,8 +364,8 @@ def set_parent(self, obj):
366
364
according to the type of "obj"
367
365
"""
368
366
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__ } " ))
371
369
loc = self ._parent_objects .index (obj .__class__ .__name__ )
372
370
parent_attr = self ._parent_attrs [loc ]
373
371
setattr (self , parent_attr , obj )
0 commit comments