Skip to content

Commit 79741e7

Browse files
committed
Fix Pylint Regressions
1 parent 926f819 commit 79741e7

29 files changed

+107
-115
lines changed

sdb/command.py

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
from sdb.target import type_canonicalize_name, type_canonical_name, type_canonicalize, get_prog
3232
from sdb.error import CommandError, SymbolNotFoundError
33-
import sdb.target as target
33+
from sdb import target
3434

3535
#
3636
# The register_command is used by the Command class when its
@@ -45,17 +45,13 @@ def register_command(name: str, class_: Type["Command"]) -> None:
4545
Register the specified command name and command class, such that the
4646
command will be available from the SDB REPL.
4747
"""
48-
# pylint: disable=global-statement
49-
global all_commands
5048
all_commands[name] = class_
5149

5250

5351
def get_registered_commands() -> Dict[str, Type["Command"]]:
5452
"""
5553
Return a dictionary of command names to command classes.
5654
"""
57-
# pylint: disable=global-statement
58-
global all_commands
5955
return all_commands
6056

6157

@@ -108,11 +104,12 @@ def help(cls, name: str) -> None:
108104
#
109105
if i == 0:
110106
line = line.replace('usage: ', '')
111-
print(" {}".format(line))
107+
print(f" {line}")
112108

113109
if len(cls.names) > 1:
110+
aliases = ", ".join(cls.names)
114111
print("ALIASES")
115-
print(" {}".format(", ".join(cls.names)))
112+
print(f" {aliases}")
116113
print()
117114

118115
indent = " "
@@ -168,7 +165,7 @@ def help(cls, name: str) -> None:
168165
f" case it will consume no objects as input; instead it"
169166
f" will locate all objects of type '{cls.output_type}',"
170167
f" and emit them as output.")
171-
types = list()
168+
types = []
172169
for (_, method) in inspect.getmembers(cls, inspect.isroutine):
173170
if hasattr(method, "input_typename_handled"):
174171
types.append(method.input_typename_handled)
@@ -203,7 +200,7 @@ def help(cls, name: str) -> None:
203200
#
204201
for line in inspect.getdoc( # type: ignore[union-attr]
205202
cls).splitlines()[2:]:
206-
print("{}".format(line))
203+
print(f"{line}")
207204
print()
208205

209206
#
@@ -588,12 +585,11 @@ class Walk(Command):
588585
def _help_message(input_type: drgn.Type = None) -> str:
589586
msg = ""
590587
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"
595591
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"
597593
return msg
598594

599595
def _call(self, objs: Iterable[drgn.Object]) -> Iterable[drgn.Object]:
@@ -645,11 +641,12 @@ def _call(self, objs: Iterable[drgn.Object]) -> Iterable[drgn.Object]:
645641
assert self.input_type is not None
646642
expected_type = type_canonicalize_name(self.input_type)
647643
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:
649646
raise CommandError(
650647
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+
)
653650

654651
yield from self.walk(obj)
655652

@@ -724,7 +721,7 @@ def caller(self, objs: Iterable[drgn.Object]) -> Iterable[drgn.Object]:
724721
out_type = None
725722
if self.output_type is not None:
726723
out_type = target.get_type(self.output_type)
727-
baked = dict()
724+
baked = {}
728725
for (_, method) in inspect.getmembers(self, inspect.ismethod):
729726
if not hasattr(method, "input_typename_handled"):
730727
continue
@@ -762,8 +759,8 @@ def caller(self, objs: Iterable[drgn.Object]) -> Iterable[drgn.Object]:
762759
pass
763760

764761
# 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_}')
767764

768765
def _call(self,
769766
objs: Iterable[drgn.Object]) -> Optional[Iterable[drgn.Object]]:

sdb/commands/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
import importlib
2121
import os
2222

23-
for path in glob.glob("{}/*.py".format(os.path.dirname(__file__))):
23+
for path in glob.glob(f"{os.path.dirname(__file__)}/*.py"):
2424
if path != __file__:
2525
module = os.path.splitext(os.path.basename(path))[0]
26-
importlib.import_module("sdb.commands.{}".format(module))
26+
importlib.import_module(f"sdb.commands.{module}")
2727

28-
for path in glob.glob("{}/*/__init__.py".format(os.path.dirname(__file__))):
28+
for path in glob.glob(f"{os.path.dirname(__file__)}/*/__init__.py"):
2929
module = os.path.basename(os.path.dirname(path))
30-
importlib.import_module("sdb.commands.{}".format(module))
30+
importlib.import_module(f"sdb.commands.{module}")

sdb/commands/filter.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ def _call_one(self, obj: drgn.Object) -> Iterable[drgn.Object]:
113113
if not isinstance(lhs, drgn.Object):
114114
raise sdb.CommandInvalidInputError(
115115
self.name,
116-
"left hand side has unsupported type ({})".format(
117-
type(lhs).__name__))
116+
f"left hand side has unsupported type ({type(lhs).__name__})"
117+
)
118118

119119
if isinstance(rhs, str):
120120
lhs = lhs.string_().decode("utf-8")
@@ -127,10 +127,10 @@ def _call_one(self, obj: drgn.Object) -> Iterable[drgn.Object]:
127127
else:
128128
raise sdb.CommandInvalidInputError(
129129
self.name,
130-
"right hand side has unsupported type ({})".format(
131-
type(rhs).__name__))
130+
f"right hand side has unsupported type ({type(rhs).__name__})"
131+
)
132132

133-
if eval("lhs {} rhs".format(self.compare), {'__builtins__': None}, {
133+
if eval(f"lhs {self.compare} rhs", {'__builtins__': None}, {
134134
'lhs': lhs,
135135
'rhs': rhs
136136
}):

sdb/commands/internal/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import importlib
2121
import os
2222

23-
for path in glob.glob("{}/*.py".format(os.path.dirname(__file__))):
23+
for path in glob.glob(f"{os.path.dirname(__file__)}/*.py"):
2424
if path != __file__:
2525
module = os.path.splitext(os.path.basename(path))[0]
26-
importlib.import_module("sdb.commands.internal.{}".format(module))
26+
importlib.import_module(f"sdb.commands.internal.{module}")

sdb/commands/linux/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
import importlib
2121
import os
2222

23-
for path in glob.glob("{}/*.py".format(os.path.dirname(__file__))):
23+
for path in glob.glob(f"{os.path.dirname(__file__)}/*.py"):
2424
if path != __file__:
2525
module = os.path.splitext(os.path.basename(path))[0]
26-
importlib.import_module("sdb.commands.linux.{}".format(module))
26+
importlib.import_module(f"sdb.commands.linux.{module}")
2727

28-
for path in glob.glob("{}/*/__init__.py".format(os.path.dirname(__file__))):
28+
for path in glob.glob(f"{os.path.dirname(__file__)}/*/__init__.py"):
2929
module = os.path.basename(os.path.dirname(path))
30-
importlib.import_module("sdb.commands.linux.{}".format(module))
30+
importlib.import_module(f"sdb.commands.linux.{module}")

sdb/commands/linux/dmesg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ def pretty_print(self, objs: Iterable[drgn.Object]) -> None:
5454
message = drgn.cast("char *", obj) + obj.type_.type.size
5555
text = message.string_().decode('utf-8', 'ignore')
5656

57-
print("[{:5d}.{:06d}]: {:s}".format(secs, usecs, text))
57+
print(f"[{secs:5d}.{usecs:06d}]: {text}")

sdb/commands/linux/internal/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import importlib
2121
import os
2222

23-
for path in glob.glob("{}/*.py".format(os.path.dirname(__file__))):
23+
for path in glob.glob(f"{os.path.dirname(__file__)}/*.py"):
2424
if path != __file__:
2525
module = os.path.splitext(os.path.basename(path))[0]
26-
importlib.import_module("sdb.commands.linux.internal.{}".format(module))
26+
importlib.import_module(f"sdb.commands.linux.internal.{module}")

sdb/commands/linux/slabs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def no_input(self) -> Iterable[drgn.Object]:
104104
# that will be the input of the next command in the pipeline.
105105
#
106106
if self.args.s and not self.islast:
107-
if self.args.s not in Slabs.FIELDS.keys():
107+
if Slabs.FIELDS[self.args.s] is None:
108108
raise sdb.CommandInvalidInputError(
109109
self.name, f"'{self.args.s}' is not a valid field")
110110
yield from sorted(
@@ -154,8 +154,8 @@ def __pp_parse_args(self) -> Tuple[str, List[str], Dict[str, Any]]:
154154

155155
for field in fields:
156156
if field not in self.FIELDS:
157-
raise sdb.CommandError(
158-
self.name, "'{:s}' is not a valid field".format(field))
157+
raise sdb.CommandError(self.name,
158+
f"'{field}' is not a valid field")
159159

160160
sort_field = ""
161161
if self.args.s:

sdb/commands/member.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,7 @@ def _parse_member_tokens(
178178
if not tokens[1].isdigit():
179179
raise sdb.CommandError(
180180
self.name,
181-
"incorrect index: '{}' is not a number".format(
182-
tokens[1]))
181+
f"incorrect index: '{tokens[1]}' is not a number")
183182
is_index = True
184183
idx = tokens[1]
185184
sep = MemberExprSep.ARRAY
@@ -191,8 +190,7 @@ def _parse_member_tokens(
191190

192191
if not is_index and not identifier.isidentifier():
193192
raise sdb.CommandError(
194-
self.name,
195-
"{} is not an acceptable identifier".format(identifier))
193+
self.name, f"{identifier} is not an acceptable identifier")
196194

197195
if not is_index:
198196
assert idx == ""
@@ -238,8 +236,8 @@ def _validate_type_dereference(self, obj: drgn.Object,
238236
if kind == drgn.TypeKind.STRUCT and sep != MemberExprSep.DOT:
239237
raise sdb.CommandError(
240238
self.name,
241-
"'{}' is a struct - use the dot(.) notation for member access".
242-
format(obj.type_))
239+
f"'{obj.type_}' is a struct - use the dot(.) notation for member access"
240+
)
243241

244242
if kind == drgn.TypeKind.POINTER:
245243
assert sep in [
@@ -249,8 +247,9 @@ def _validate_type_dereference(self, obj: drgn.Object,
249247

250248
if kind == drgn.TypeKind.ARRAY and sep != MemberExprSep.ARRAY:
251249
raise sdb.CommandError(
252-
self.name, "'{}' is an array - cannot use '{}' notation".format(
253-
obj.type_, sep.value))
250+
self.name,
251+
f"'{obj.type_}' is an array - cannot use '{sep.value}' notation"
252+
)
254253

255254
def _validate_array_index(self, type_: drgn.Type, idx: int) -> None:
256255
"""

sdb/commands/pretty_print.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ def _call(self, objs: Iterable[drgn.Object]) -> None:
4141

4242
if handling_class is None:
4343
if first_obj_type is not None:
44-
msg = 'could not find pretty-printer for type {}\n'.format(
45-
first_obj_type)
44+
msg = f'could not find pretty-printer for type {first_obj_type}\n'
4645
else:
4746
msg = 'could not find pretty-printer\n'
4847
msg += "The following types have pretty-printers:\n"

0 commit comments

Comments
 (0)