30
30
31
31
from sdb .target import type_canonicalize_name , type_canonical_name , type_canonicalize , get_prog
32
32
from sdb .error import CommandError , SymbolNotFoundError
33
- import sdb . target as target
33
+ from sdb import target
34
34
35
35
#
36
36
# The register_command is used by the Command class when its
@@ -45,17 +45,13 @@ def register_command(name: str, class_: Type["Command"]) -> None:
45
45
Register the specified command name and command class, such that the
46
46
command will be available from the SDB REPL.
47
47
"""
48
- # pylint: disable=global-statement
49
- global all_commands
50
48
all_commands [name ] = class_
51
49
52
50
53
51
def get_registered_commands () -> Dict [str , Type ["Command" ]]:
54
52
"""
55
53
Return a dictionary of command names to command classes.
56
54
"""
57
- # pylint: disable=global-statement
58
- global all_commands
59
55
return all_commands
60
56
61
57
@@ -108,11 +104,12 @@ def help(cls, name: str) -> None:
108
104
#
109
105
if i == 0 :
110
106
line = line .replace ('usage: ' , '' )
111
- print (" {}" . format ( line ) )
107
+ print (f " { line } " )
112
108
113
109
if len (cls .names ) > 1 :
110
+ aliases = ", " .join (cls .names )
114
111
print ("ALIASES" )
115
- print (" {}" . format ( ", " . join ( cls . names )) )
112
+ print (f " { aliases } " )
116
113
print ()
117
114
118
115
indent = " "
@@ -168,7 +165,7 @@ def help(cls, name: str) -> None:
168
165
f" case it will consume no objects as input; instead it"
169
166
f" will locate all objects of type '{ cls .output_type } ',"
170
167
f" and emit them as output." )
171
- types = list ()
168
+ types = []
172
169
for (_ , method ) in inspect .getmembers (cls , inspect .isroutine ):
173
170
if hasattr (method , "input_typename_handled" ):
174
171
types .append (method .input_typename_handled )
@@ -203,7 +200,7 @@ def help(cls, name: str) -> None:
203
200
#
204
201
for line in inspect .getdoc ( # type: ignore[union-attr]
205
202
cls ).splitlines ()[2 :]:
206
- print ("{}" . format ( line ) )
203
+ print (f" { line } " )
207
204
print ()
208
205
209
206
#
@@ -588,12 +585,11 @@ class Walk(Command):
588
585
def _help_message (input_type : drgn .Type = None ) -> str :
589
586
msg = ""
590
587
if input_type is not None :
591
- msg = msg + "no walker found for input of type {}\n " .format (
592
- input_type )
593
- msg = msg + "The following types have walkers:\n "
594
- msg = msg + "\t %-20s %-20s\n " % ("WALKER" , "TYPE" )
588
+ msg += f"no walker found for input of type { input_type } \n "
589
+ msg += "The following types have walkers:\n "
590
+ msg += f"\t { 'WALKER' :-20s} { 'TYPE' :-20s} \n "
595
591
for type_ , class_ in Walker .allWalkers .items ():
596
- msg = msg + "\t %-20s %-20s \n " % ( class_ .names [0 ], type_ )
592
+ msg += f "\t { class_ .names [0 ]:-20s } { type_ :-20s } \n "
597
593
return msg
598
594
599
595
def _call (self , objs : Iterable [drgn .Object ]) -> Iterable [drgn .Object ]:
@@ -645,11 +641,12 @@ def _call(self, objs: Iterable[drgn.Object]) -> Iterable[drgn.Object]:
645
641
assert self .input_type is not None
646
642
expected_type = type_canonicalize_name (self .input_type )
647
643
for obj in objs :
648
- if type_canonical_name (obj .type_ ) != expected_type :
644
+ canonical_type = type_canonical_name (obj .type_ )
645
+ if canonical_type != expected_type :
649
646
raise CommandError (
650
647
self .name ,
651
- 'expected input of type {}, but received {}' . format (
652
- expected_type , type_canonical_name ( obj . type_ )) )
648
+ f 'expected input of type { expected_type } , but received { canonical_type } '
649
+ )
653
650
654
651
yield from self .walk (obj )
655
652
@@ -724,7 +721,7 @@ def caller(self, objs: Iterable[drgn.Object]) -> Iterable[drgn.Object]:
724
721
out_type = None
725
722
if self .output_type is not None :
726
723
out_type = target .get_type (self .output_type )
727
- baked = dict ()
724
+ baked = {}
728
725
for (_ , method ) in inspect .getmembers (self , inspect .ismethod ):
729
726
if not hasattr (method , "input_typename_handled" ):
730
727
continue
@@ -762,8 +759,8 @@ def caller(self, objs: Iterable[drgn.Object]) -> Iterable[drgn.Object]:
762
759
pass
763
760
764
761
# error
765
- raise CommandError (
766
- self . name , 'no handler for input of type {}' . format ( i .type_ ) )
762
+ raise CommandError (self . name ,
763
+ f 'no handler for input of type { i .type_ } ' )
767
764
768
765
def _call (self ,
769
766
objs : Iterable [drgn .Object ]) -> Optional [Iterable [drgn .Object ]]:
0 commit comments