Skip to content

Commit 909ef57

Browse files
committed
Upgrade string formatting
ruff check --select=UP031,UP032,FLY --fix
1 parent 0196ff0 commit 909ef57

File tree

8 files changed

+23
-30
lines changed

8 files changed

+23
-30
lines changed

docs/conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@
4646

4747
intersphinx_mapping = {
4848
"commandsv1": (
49-
"https://robotpy.readthedocs.io/projects/commands-v1/en/%s/" % rtd_version,
49+
f"https://robotpy.readthedocs.io/projects/commands-v1/en/{rtd_version}/",
5050
None,
5151
),
5252
"networktables": (
53-
"https://robotpy.readthedocs.io/projects/pynetworktables/en/%s/" % rtd_version,
53+
f"https://robotpy.readthedocs.io/projects/pynetworktables/en/{rtd_version}/",
5454
None,
5555
),
5656
"wpilib": (
57-
"https://robotpy.readthedocs.io/projects/wpilib/en/%s/" % rtd_version,
57+
f"https://robotpy.readthedocs.io/projects/wpilib/en/{rtd_version}/",
5858
None,
5959
),
6060
}

magicbot/inject.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,13 @@ def find_injections(
7373
# Raise error if injectable syntax used but no injectable was found.
7474
if injectable is None:
7575
raise MagicInjectError(
76-
"Component %s has variable %s (type %s), which is absent from robot"
77-
% (cname, n, inject_type)
76+
f"Component {cname} has variable {n} (type {inject_type}), which is absent from robot"
7877
)
7978

8079
# Raise error if injectable declared with type different than the initial type
8180
if not isinstance(injectable, inject_type):
8281
raise MagicInjectError(
83-
"Component %s variable %s does not match type in robot! (Got %s, expected %s)"
84-
% (cname, n, type(injectable), inject_type)
82+
f"Component {cname} variable {n} does not match type in robot! (Got {type(injectable)}, expected {inject_type})"
8583
)
8684

8785
to_inject[n] = injectable

magicbot/magic_tunable.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ def setup_tunables(component, cname: str, prefix: Optional[str] = "components")
185185
cls = component.__class__
186186

187187
if prefix is None:
188-
prefix = "/%s" % cname
188+
prefix = f"/{cname}"
189189
else:
190-
prefix = "/%s/%s" % (prefix, cname)
190+
prefix = f"/{prefix}/{cname}"
191191

192192
NetworkTables = NetworkTableInstance.getDefault()
193193

@@ -202,9 +202,9 @@ def setup_tunables(component, cname: str, prefix: Optional[str] = "components")
202202
continue
203203

204204
if prop._ntsubtable:
205-
key = "%s/%s/%s" % (prefix, prop._ntsubtable, n)
205+
key = f"{prefix}/{prop._ntsubtable}/{n}"
206206
else:
207-
key = "%s/%s" % (prefix, n)
207+
key = f"{prefix}/{n}"
208208

209209
topic = prop._topic_type(NetworkTables.getTopic(key))
210210
ntvalue = topic.getEntry(prop._ntdefault)
@@ -344,9 +344,9 @@ def collect_feedbacks(component, cname: str, prefix: Optional[str] = "components
344344
.. note:: This isn't useful for normal use.
345345
"""
346346
if prefix is None:
347-
prefix = "/%s" % cname
347+
prefix = f"/{cname}"
348348
else:
349-
prefix = "/%s/%s" % (prefix, cname)
349+
prefix = f"/{prefix}/{cname}"
350350

351351
nt = NetworkTableInstance.getDefault().getTable(prefix)
352352
feedbacks = []

magicbot/magicrobot.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,7 @@ def _create_components(self) -> None:
609609
# If the type is not actually a type, give a meaningful error
610610
if not isinstance(ctyp, type):
611611
raise TypeError(
612-
"%s has a non-type annotation on %s (%r); lone non-injection variable annotations are disallowed, did you want to assign a static variable?"
613-
% (cls.__name__, m, ctyp)
612+
f"{cls.__name__} has a non-type annotation on {m} ({ctyp!r}); lone non-injection variable annotations are disallowed, did you want to assign a static variable?"
614613
)
615614

616615
component = self._create_component(m, ctyp, injectables)
@@ -690,8 +689,7 @@ def _create_component(self, name: str, ctyp: type, injectables: Dict[str, Any]):
690689
# Ensure that mandatory methods are there
691690
if not callable(getattr(component, "execute", None)):
692691
raise ValueError(
693-
"Component %s (%r) must have a method named 'execute'"
694-
% (name, component)
692+
f"Component {name} ({component!r}) must have a method named 'execute'"
695693
)
696694

697695
# Automatically inject a logger object

magicbot/state_machine.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def __init__(
8484

8585
if invalid_args:
8686
raise ValueError(
87-
"Invalid parameter names in %s: %s" % (name, ",".join(invalid_args))
87+
"Invalid parameter names in {}: {}".format(name, ",".join(invalid_args))
8888
)
8989

9090
self.name = name
@@ -135,7 +135,7 @@ def __set_name__(self, owner: type, name: str) -> None:
135135
class _StateData:
136136
def __init__(self, wrapper: _State) -> None:
137137
self.name = wrapper.name
138-
self.duration_attr = "%s_duration" % self.name
138+
self.duration_attr = f"{self.name}_duration"
139139
self.expires: float = 0xFFFFFFFF
140140
self.ran = False
141141
self.run = wrapper.run

robotpy_ext/autonomous/selector.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def __init__(self, autonomous_pkgname, *args, **kwargs):
151151
if mode_name in self.modes:
152152
if not wpilib.DriverStation.isFMSAttached():
153153
raise RuntimeError(
154-
"Duplicate name %s in %s" % (mode_name, module_filename)
154+
f"Duplicate name {mode_name} in {module_filename}"
155155
)
156156

157157
logger.error(
@@ -195,8 +195,7 @@ def __init__(self, autonomous_pkgname, *args, **kwargs):
195195
elif len(default_modes) != 1:
196196
if not wpilib.DriverStation.isFMSAttached():
197197
raise RuntimeError(
198-
"More than one autonomous mode was specified as default! (modes: %s)"
199-
% (", ".join(default_modes))
198+
"More than one autonomous mode was specified as default! (modes: {})".format(", ".join(default_modes))
200199
)
201200

202201
# must PutData after setting up objects

robotpy_ext/autonomous/stateful_autonomous.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def __init__(self, f: Callable, first: bool):
3939
)
4040
if arg.kind is arg.KEYWORD_ONLY:
4141
raise ValueError(
42-
"Cannot use keyword-only parameters for function %s" % name
42+
f"Cannot use keyword-only parameters for function {name}"
4343
)
4444
if arg.name in allowed_args:
4545
args.append(arg.name)
@@ -48,7 +48,7 @@ def __init__(self, f: Callable, first: bool):
4848

4949
if invalid_args:
5050
raise ValueError(
51-
"Invalid parameter names in %s: %s" % (name, ",".join(invalid_args))
51+
"Invalid parameter names in {}: {}".format(name, ",".join(invalid_args))
5252
)
5353

5454
functools.update_wrapper(self, f)
@@ -271,22 +271,22 @@ def register_sd_var(self, name, default, add_prefix=True, vmin=-1, vmax=1):
271271

272272
# communicate the min/max value for numbers to the dashboard
273273
if is_number:
274-
name = "%s|%0.3f|%0.3f" % (name, vmin, vmax)
274+
name = f"{name}|{vmin:0.3f}|{vmax:0.3f}"
275275

276276
self.__tunables.append(name)
277277
self.__table.putStringArray(self.MODE_NAME + "_tunables", self.__tunables)
278278

279279
def __register_sd_var_internal(self, name, default, add_prefix, readback):
280280
if " " in name:
281281
raise ValueError(
282-
"ERROR: Cannot use spaces in a tunable variable name (%s)" % name
282+
f"ERROR: Cannot use spaces in a tunable variable name ({name})"
283283
)
284284

285285
is_number = False
286286
sd_name = name
287287

288288
if add_prefix:
289-
sd_name = "%s\\%s" % (self.MODE_NAME, name)
289+
sd_name = f"{self.MODE_NAME}\\{name}"
290290

291291
if isinstance(default, bool):
292292
self.__table.putBoolean(sd_name, default)

robotpy_ext/common_drivers/driver_base.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,5 @@ def __init__(self):
1616
"""
1717
if not self.verified:
1818
print(
19-
"Warning, device driver {} has not been verified yet, please use with caution!".format(
20-
self.__class__.__name__
21-
)
19+
f"Warning, device driver {self.__class__.__name__} has not been verified yet, please use with caution!"
2220
)

0 commit comments

Comments
 (0)