@@ -386,6 +386,14 @@ def _detect_replacable_format_call(self, node: nodes.Const) -> None:
386
386
if not isinstance (node .parent .parent , nodes .Call ):
387
387
return
388
388
389
+ # Don't raise message on bad format string
390
+ try :
391
+ keyword_args = [
392
+ i [0 ] for i in utils .parse_format_method_string (node .value )[0 ]
393
+ ]
394
+ except utils .IncompleteFormatString :
395
+ return
396
+
389
397
if node .parent .parent .args :
390
398
for arg in node .parent .parent .args :
391
399
# If star expressions with more than 1 element are being used
@@ -401,9 +409,6 @@ def _detect_replacable_format_call(self, node: nodes.Const) -> None:
401
409
return
402
410
403
411
elif node .parent .parent .keywords :
404
- keyword_args = [
405
- i [0 ] for i in utils .parse_format_method_string (node .value )[0 ]
406
- ]
407
412
for keyword in node .parent .parent .keywords :
408
413
# If keyword is used multiple times
409
414
if keyword_args .count (keyword .arg ) > 1 :
@@ -412,9 +417,12 @@ def _detect_replacable_format_call(self, node: nodes.Const) -> None:
412
417
keyword = utils .safe_infer (keyword .value )
413
418
414
419
# If lists of more than one element are being unpacked
415
- if isinstance (keyword , nodes .Dict ):
416
- if len (keyword .items ) > 1 and len (keyword_args ) > 1 :
417
- return
420
+ if (
421
+ isinstance (keyword , nodes .Dict )
422
+ and len (keyword .items ) > 1
423
+ and len (keyword_args ) > 1
424
+ ):
425
+ return
418
426
419
427
# If all tests pass, then raise message
420
428
self .add_message (
@@ -442,12 +450,10 @@ def _detect_replacable_format_call(self, node: nodes.Const) -> None:
442
450
inferred_right = utils .safe_infer (node .parent .right )
443
451
444
452
# If dicts or lists of length > 1 are used
445
- if isinstance (inferred_right , nodes .Dict ):
446
- if len (inferred_right .items ) > 1 :
447
- return
448
- elif isinstance (inferred_right , nodes .List ):
449
- if len (inferred_right .elts ) > 1 :
450
- return
453
+ if isinstance (inferred_right , nodes .Dict ) and len (inferred_right .items ) > 1 :
454
+ return
455
+ if isinstance (inferred_right , nodes .List ) and len (inferred_right .elts ) > 1 :
456
+ return
451
457
452
458
# If all tests pass, then raise message
453
459
self .add_message (
0 commit comments