Skip to content

Commit 34bc4c3

Browse files
rruuaanngkartben
authored andcommitted
style: edtlib: Use a better format string
Use f-strings as recommended by PEP-8 instead of the .format() method. Signed-off-by: James Roy <[email protected]>
1 parent d20140d commit 34bc4c3

File tree

3 files changed

+28
-39
lines changed

3 files changed

+28
-39
lines changed

.ruff-excludes.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,6 @@
440440
"I001", # https://docs.astral.sh/ruff/rules/unsorted-imports
441441
"SIM201", # https://docs.astral.sh/ruff/rules/negate-equal-op
442442
"UP007", # https://docs.astral.sh/ruff/rules/non-pep604-annotation
443-
"UP032", # https://docs.astral.sh/ruff/rules/f-string
444443
"UP035", # https://docs.astral.sh/ruff/rules/deprecated-import
445444
"UP037", # https://docs.astral.sh/ruff/rules/quoted-annotation
446445
]
@@ -453,7 +452,6 @@
453452
"SIM118", # https://docs.astral.sh/ruff/rules/in-dict-keys
454453
"UP007", # https://docs.astral.sh/ruff/rules/non-pep604-annotation
455454
"UP015", # https://docs.astral.sh/ruff/rules/redundant-open-modes
456-
"UP032", # https://docs.astral.sh/ruff/rules/f-string
457455
"UP035", # https://docs.astral.sh/ruff/rules/deprecated-import
458456
"UP037", # https://docs.astral.sh/ruff/rules/quoted-annotation
459457
]

scripts/dts/python-devicetree/src/devicetree/dtlib.py

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,9 @@ def to_num(self, signed=False) -> int:
381381
unsigned.
382382
"""
383383
if self.type is not Type.NUM:
384-
_err("expected property '{0}' on {1} in {2} to be assigned with "
385-
"'{0} = < (number) >;', not '{3}'"
386-
.format(self.name, self.node.path, self.node.dt.filename,
387-
self))
384+
_err(f"expected property '{self.name}' on {self.node.path} in "
385+
f"{self.node.dt.filename} to be assigned with "
386+
f"'{self.name} = < (number) >;', not '{self}'")
388387

389388
return int.from_bytes(self.value, "big", signed=signed)
390389

@@ -402,10 +401,9 @@ def to_nums(self, signed=False) -> list[int]:
402401
unsigned.
403402
"""
404403
if self.type not in (Type.NUM, Type.NUMS):
405-
_err("expected property '{0}' on {1} in {2} to be assigned with "
406-
"'{0} = < (number) (number) ... >;', not '{3}'"
407-
.format(self.name, self.node.path, self.node.dt.filename,
408-
self))
404+
_err(f"expected property '{self.name}' on {self.node.path} in "
405+
f"{self.node.dt.filename} to be assigned with "
406+
f"'{self.name} = < (number) (number) ... >;', not '{self}'")
409407

410408
return [int.from_bytes(self.value[i:i + 4], "big", signed=signed)
411409
for i in range(0, len(self.value), 4)]
@@ -421,10 +419,9 @@ def to_bytes(self) -> bytes:
421419
foo = [ 01 ... ];
422420
"""
423421
if self.type is not Type.BYTES:
424-
_err("expected property '{0}' on {1} in {2} to be assigned with "
425-
"'{0} = [ (byte) (byte) ... ];', not '{3}'"
426-
.format(self.name, self.node.path, self.node.dt.filename,
427-
self))
422+
_err(f"expected property '{self.name}' on {self.node.path} "
423+
f"in {self.node.dt.filename} to be assigned with "
424+
f"'{self.name} = [ (byte) (byte) ... ];', not '{self}'")
428425

429426
return self.value
430427

@@ -441,10 +438,9 @@ def to_string(self) -> str:
441438
not valid UTF-8.
442439
"""
443440
if self.type is not Type.STRING:
444-
_err("expected property '{0}' on {1} in {2} to be assigned with "
445-
"'{0} = \"string\";', not '{3}'"
446-
.format(self.name, self.node.path, self.node.dt.filename,
447-
self))
441+
_err(f"expected property '{self.name}' on {self.node.path} "
442+
f"in {self.node.dt.filename} to be assigned with "
443+
f"'{self.name} = \"string\";', not '{self}'")
448444

449445
try:
450446
ret = self.value.decode("utf-8")[:-1] # Strip null
@@ -467,10 +463,9 @@ def to_strings(self) -> list[str]:
467463
Also raises DTError if any of the strings are not valid UTF-8.
468464
"""
469465
if self.type not in (Type.STRING, Type.STRINGS):
470-
_err("expected property '{0}' on {1} in {2} to be assigned with "
471-
"'{0} = \"string\", \"string\", ... ;', not '{3}'"
472-
.format(self.name, self.node.path, self.node.dt.filename,
473-
self))
466+
_err(f"expected property '{self.name}' on {self.node.path} in "
467+
f"{self.node.dt.filename} to be assigned with "
468+
f"'{self.name} = \"string\", \"string\", ... ;', not '{self}'")
474469

475470
try:
476471
ret = self.value.decode("utf-8").split("\0")[:-1]
@@ -491,10 +486,9 @@ def to_node(self) -> Node:
491486
foo = < &bar >;
492487
"""
493488
if self.type is not Type.PHANDLE:
494-
_err("expected property '{0}' on {1} in {2} to be assigned with "
495-
"'{0} = < &foo >;', not '{3}'"
496-
.format(self.name, self.node.path, self.node.dt.filename,
497-
self))
489+
_err(f"expected property '{self.name}' on {self.node.path} in "
490+
f"{self.node.dt.filename} to be assigned with "
491+
f"'{self.name} = < &foo >;', not '{self}'")
498492

499493
return self.node.dt.phandle2node[int.from_bytes(self.value, "big")]
500494

@@ -517,10 +511,9 @@ def type_ok():
517511
return self.type is Type.NUMS and not self.value
518512

519513
if not type_ok():
520-
_err("expected property '{0}' on {1} in {2} to be assigned with "
521-
"'{0} = < &foo &bar ... >;', not '{3}'"
522-
.format(self.name, self.node.path,
523-
self.node.dt.filename, self))
514+
_err(f"expected property '{self.name}' on {self.node.path} in "
515+
f"{self.node.dt.filename} to be assigned with "
516+
f"'{self.name} = < &foo &bar ... >;', not '{self}'")
524517

525518
return [self.node.dt.phandle2node[int.from_bytes(self.value[i:i + 4],
526519
"big")]
@@ -539,10 +532,10 @@ def to_path(self) -> Node:
539532
For the second case, DTError is raised if the path does not exist.
540533
"""
541534
if self.type not in (Type.PATH, Type.STRING):
542-
_err("expected property '{0}' on {1} in {2} to be assigned with "
543-
"either '{0} = &foo' or '{0} = \"/path/to/node\"', not '{3}'"
544-
.format(self.name, self.node.path, self.node.dt.filename,
545-
self))
535+
_err(f"expected property '{self.name}' on {self.node.path} in "
536+
f"{self.node.dt.filename} to be assigned with either "
537+
f"'{self.name} = &foo' or '{self.name} = \"/path/to/node\"', "
538+
f"not '{self}'")
546539

547540
try:
548541
path = self.value.decode("utf-8")[:-1]

scripts/dts/python-devicetree/src/devicetree/edtlib.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,11 +1533,9 @@ def _prop_val(
15331533

15341534
if prop_type == "boolean":
15351535
if prop.type != Type.EMPTY:
1536-
_err(
1537-
"'{0}' in {1!r} is defined with 'type: boolean' in {2}, "
1538-
"but is assigned a value ('{3}') instead of being empty "
1539-
"('{0};')".format(name, node, binding_path, prop)
1540-
)
1536+
_err(f"'{name}' in {node!r} is defined with 'type: boolean' "
1537+
f"in {binding_path}, but is assigned a value ('{prop}') "
1538+
f"instead of being empty ('{name};')")
15411539
return True
15421540

15431541
if prop_type == "int":

0 commit comments

Comments
 (0)