@@ -82,21 +82,21 @@ class YappiError(Exception):
82
82
def _validate_sorttype (sort_type , list ):
83
83
sort_type = sort_type .lower ()
84
84
if sort_type not in list :
85
- raise YappiError ("Invalid SortType parameter: '%s'" % ( sort_type ) )
85
+ raise YappiError (f "Invalid SortType parameter: '{ sort_type } '" )
86
86
return sort_type
87
87
88
88
89
89
def _validate_sortorder (sort_order ):
90
90
sort_order = sort_order .lower ()
91
91
if sort_order not in SORT_ORDERS :
92
- raise YappiError ("Invalid SortOrder parameter: '%s'" % ( sort_order ) )
92
+ raise YappiError (f "Invalid SortOrder parameter: '{ sort_order } '" )
93
93
return sort_order
94
94
95
95
96
96
def _validate_columns (name , list ):
97
97
name = name .lower ()
98
98
if name not in list :
99
- raise YappiError ("Invalid Column name: '%s'" % ( name ) )
99
+ raise YappiError (f "Invalid Column name: '{ name } '" )
100
100
101
101
102
102
def _ctx_name_callback ():
@@ -134,7 +134,7 @@ def _create_greenlet_callbacks():
134
134
try :
135
135
from greenlet import getcurrent
136
136
except ImportError as exc :
137
- raise YappiError ("'greenlet' import failed with: %s" % repr (exc ))
137
+ raise YappiError (f "'greenlet' import failed with: { repr (exc )} " )
138
138
139
139
def _get_greenlet_id ():
140
140
curr_greenlet = getcurrent ()
@@ -175,12 +175,12 @@ def module_matches(stat, modules):
175
175
176
176
if not isinstance (stat , YStat ):
177
177
raise YappiError (
178
- "Argument 'stat' shall be a YStat object. (%s)" % ( stat )
178
+ f "Argument 'stat' shall be a YStat object. ({ stat } )"
179
179
)
180
180
181
181
if not isinstance (modules , list ):
182
182
raise YappiError (
183
- "Argument 'modules' is not a list object. (%s)" % ( modules )
183
+ f "Argument 'modules' is not a list object. ({ modules } )"
184
184
)
185
185
186
186
if not len (modules ):
@@ -192,7 +192,7 @@ def module_matches(stat, modules):
192
192
modules = set (modules )
193
193
for module in modules :
194
194
if not isinstance (module , types .ModuleType ):
195
- raise YappiError ("Non-module item in 'modules'. (%s)" % ( module ) )
195
+ raise YappiError (f "Non-module item in 'modules'. ({ module } )" )
196
196
return inspect .getmodule (_fn_descriptor_dict [stat .full_name ]) in modules
197
197
198
198
@@ -211,12 +211,12 @@ def func_matches(stat, funcs):
211
211
212
212
if not isinstance (stat , YStat ):
213
213
raise YappiError (
214
- "Argument 'stat' shall be a YStat object. (%s)" % ( stat )
214
+ f "Argument 'stat' shall be a YStat object. ({ stat } )"
215
215
)
216
216
217
217
if not isinstance (funcs , list ):
218
218
raise YappiError (
219
- "Argument 'funcs' is not a list object. (%s)" % ( funcs )
219
+ f "Argument 'funcs' is not a list object. ({ funcs } )"
220
220
)
221
221
222
222
if not len (funcs ):
@@ -228,7 +228,7 @@ def func_matches(stat, funcs):
228
228
funcs = set (funcs )
229
229
for func in funcs .copy ():
230
230
if not callable (func ):
231
- raise YappiError ("Non-callable item in 'funcs'. (%s)" % ( func ) )
231
+ raise YappiError (f "Non-callable item in 'funcs'. ({ func } )" )
232
232
233
233
# If there is no CodeObject found, use func itself. It might be a
234
234
# method descriptor, builtin func..etc.
@@ -877,8 +877,7 @@ def _add_from_YSTAT(self, file):
877
877
saved_stats , saved_clock_type = pickle .load (file )
878
878
except :
879
879
raise YappiError (
880
- "Unable to load the saved profile information from %s." %
881
- (file .name )
880
+ f"Unable to load the saved profile information from { file .name } ."
882
881
)
883
882
884
883
# check if we really have some stats to be merged?
@@ -996,7 +995,7 @@ def add(self, files, type="ystat"):
996
995
]
997
996
for fd in files :
998
997
with open (fd , "rb" ) as f :
999
- add_func = getattr (self , "_add_from_%s" % ( type ) )
998
+ add_func = getattr (self , f "_add_from_{ type } " )
1000
999
add_func (file = f )
1001
1000
1002
1001
return self .sort (DEFAULT_SORT_TYPE , DEFAULT_SORT_ORDER )
@@ -1005,10 +1004,10 @@ def save(self, path, type="ystat"):
1005
1004
type = type .upper ()
1006
1005
if type not in self ._SUPPORTED_SAVE_FORMATS :
1007
1006
raise NotImplementedError (
1008
- 'Saving in "%s " format is not possible currently.' % ( type )
1007
+ f 'Saving in "{ type } " format is not possible currently.'
1009
1008
)
1010
1009
1011
- save_func = getattr (self , "_save_as_%s" % ( type ) )
1010
+ save_func = getattr (self , f "_save_as_{ type } " )
1012
1011
save_func (path = path )
1013
1012
1014
1013
def print_all (
@@ -1032,7 +1031,7 @@ def print_all(
1032
1031
_validate_columns (col [0 ], COLUMNS_FUNCSTATS )
1033
1032
1034
1033
out .write (LINESEP )
1035
- out .write ("Clock type: %s" % ( self ._clock_type .upper ()) )
1034
+ out .write (f "Clock type: { self ._clock_type .upper ()} " )
1036
1035
out .write (LINESEP )
1037
1036
out .write (f"Ordered by: { self ._sort_type } , { self ._sort_order } " )
1038
1037
out .write (LINESEP )
@@ -1062,13 +1061,13 @@ def debug_print(self):
1062
1061
for stat in self :
1063
1062
console .write ("index: %d" % stat .index )
1064
1063
console .write (LINESEP )
1065
- console .write ("full_name: %s" % stat .full_name )
1064
+ console .write (f "full_name: { stat .full_name } " )
1066
1065
console .write (LINESEP )
1067
1066
console .write ("ncall: %d/%d" % (stat .ncall , stat .nactualcall ))
1068
1067
console .write (LINESEP )
1069
- console .write ("ttot: %s" % _fft (stat .ttot ))
1068
+ console .write (f "ttot: { _fft (stat .ttot )} " )
1070
1069
console .write (LINESEP )
1071
- console .write ("tsub: %s" % _fft (stat .tsub ))
1070
+ console .write (f "tsub: { _fft (stat .tsub )} " )
1072
1071
console .write (LINESEP )
1073
1072
console .write ("children: " )
1074
1073
console .write (LINESEP )
@@ -1078,18 +1077,18 @@ def debug_print(self):
1078
1077
console .write ("index: %d" % child_stat .index )
1079
1078
console .write (LINESEP )
1080
1079
console .write (" " * CHILD_STATS_LEFT_MARGIN )
1081
- console .write ("child_full_name: %s" % child_stat .full_name )
1080
+ console .write (f "child_full_name: { child_stat .full_name } " )
1082
1081
console .write (LINESEP )
1083
1082
console .write (" " * CHILD_STATS_LEFT_MARGIN )
1084
1083
console .write (
1085
1084
"ncall: %d/%d" % (child_stat .ncall , child_stat .nactualcall )
1086
1085
)
1087
1086
console .write (LINESEP )
1088
1087
console .write (" " * CHILD_STATS_LEFT_MARGIN )
1089
- console .write ("ttot: %s" % _fft (child_stat .ttot ))
1088
+ console .write (f "ttot: { _fft (child_stat .ttot )} " )
1090
1089
console .write (LINESEP )
1091
1090
console .write (" " * CHILD_STATS_LEFT_MARGIN )
1092
- console .write ("tsub: %s" % _fft (child_stat .tsub ))
1091
+ console .write (f "tsub: { _fft (child_stat .tsub )} " )
1093
1092
console .write (LINESEP )
1094
1093
console .write (LINESEP )
1095
1094
@@ -1353,7 +1352,7 @@ def set_clock_type(type):
1353
1352
"""
1354
1353
type = type .upper ()
1355
1354
if type not in CLOCK_TYPES :
1356
- raise YappiError ("Invalid clock type:%s" % ( type ) )
1355
+ raise YappiError (f "Invalid clock type:{ type } " )
1357
1356
1358
1357
_yappi .set_clock_type (CLOCK_TYPES [type ])
1359
1358
@@ -1391,7 +1390,7 @@ def set_context_backend(type):
1391
1390
"""
1392
1391
type = type .upper ()
1393
1392
if type not in BACKEND_TYPES :
1394
- raise YappiError ("Invalid backend type: %s" % ( type ) )
1393
+ raise YappiError (f "Invalid backend type: { type } " )
1395
1394
1396
1395
if type == GREENLET :
1397
1396
id_cbk , name_cbk = _create_greenlet_callbacks ()
0 commit comments