Skip to content

Commit 2acc9f7

Browse files
alexfiklinducer
authored andcommitted
feat: use f-strings in tools.py
1 parent b0d8c91 commit 2acc9f7

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

pyopencl/tools.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -638,9 +638,9 @@ def __call__(self):
638638
@override
639639
def __str__(self) -> str:
640640
# Don't show address, so that parallel test collection works
641-
return ("<context factory for <pyopencl.Device '%s' on '%s'>>" %
642-
(self.device.name.strip(),
643-
self.device.platform.name.strip()))
641+
device = self.device.name.strip()
642+
platform = self.device.platform.name.strip()
643+
return f"<context factory for <pyopencl.Device '{device}' on '{platform}'>>"
644644

645645

646646
DeviceOrPlatformT = TypeVar("DeviceOrPlatformT", "cl.Device", "cl.Platform")
@@ -660,7 +660,7 @@ def _find_cl_obj(
660660
for obj in objs:
661661
if identifier.lower() in (obj.name + " " + obj.vendor).lower():
662662
return obj
663-
raise RuntimeError("object '%s' not found" % identifier)
663+
raise RuntimeError(f"object '{identifier}' not found")
664664

665665

666666
def get_test_platforms_and_devices(
@@ -943,12 +943,12 @@ def get_arg_offset_adjuster_code(arg_types: Sequence[Argument]) -> str:
943943

944944
for arg_type in arg_types:
945945
if isinstance(arg_type, VectorArg) and arg_type.with_offset:
946-
result.append("__global %(type)s *%(name)s = "
947-
"(__global %(type)s *) "
948-
"((__global char *) %(name)s__base + %(name)s__offset);"
949-
% {
950-
"type": dtype_to_ctype(arg_type.dtype),
951-
"name": arg_type.name})
946+
name = arg_type.name
947+
ctype = dtype_to_ctype(arg_type.dtype)
948+
result.append(
949+
f"__global {ctype} *{name} = "
950+
f"(__global {ctype} *) "
951+
f"((__global char *) {name}__base + {name}__offset);")
952952

953953
return "\n".join(result)
954954

@@ -1135,9 +1135,9 @@ def match_dtype_to_c_struct(
11351135
dims_str = ""
11361136
try:
11371137
for dim in array_dims:
1138-
dims_str += "[%d]" % dim
1138+
dims_str += f"[{dim}]"
11391139
except TypeError:
1140-
dims_str = "[%d]" % array_dims
1140+
dims_str = f"[{array_dims}]"
11411141
c_fields.append(" {} {}{};".format(
11421142
dtype_to_ctype(array_dtype), field_name, dims_str)
11431143
)
@@ -1477,7 +1477,7 @@ def vec_arg_factory(
14771477
assert isinstance(arg[1], str)
14781478
parsed_arg = ScalarArg(self.parse_type(arg[0]), arg[1])
14791479
else:
1480-
raise TypeError("unexpected argument type: %s" % type(arg))
1480+
raise TypeError(f"unexpected argument type: {type(arg)}")
14811481

14821482
parsed_args.append(parsed_arg)
14831483

0 commit comments

Comments
 (0)