Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update pre-commit hooks #2585

Merged
merged 5 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ repos:
additional_dependencies: [pyyaml]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.277
rev: v0.0.281
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
Expand Down Expand Up @@ -74,6 +74,6 @@ repos:


- repo: https://github.com/asottile/pyupgrade
rev: v3.9.0
rev: v3.10.1
hooks:
- id: pyupgrade
12 changes: 4 additions & 8 deletions dev/generate-kernel-signatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def include_kernels_h(specification):
"w",
) as header:
header.write(
"""// AUTO GENERATED ON {0}
f"""// AUTO GENERATED ON {reproducible_datetime()}
// DO NOT EDIT BY HAND!
//
// To regenerate file, run
Expand All @@ -146,9 +146,7 @@ def include_kernels_h(specification):

extern "C" {{

""".format(
reproducible_datetime()
)
"""
)
for spec in specification["kernels"]:
for childfunc in spec["specializations"]:
Expand Down Expand Up @@ -217,7 +215,7 @@ def kernel_signatures_py(specification):
"w",
) as file:
file.write(
"""# AUTO GENERATED ON {0}
f"""# AUTO GENERATED ON {reproducible_datetime()}
# DO NOT EDIT BY HAND!
#
# To regenerate file, run
Expand Down Expand Up @@ -272,9 +270,7 @@ class ERROR(Structure):

def by_signature(lib):
out = {{}}
""".format(
reproducible_datetime()
)
"""
)

for spec in specification["kernels"]:
Expand Down
36 changes: 12 additions & 24 deletions dev/generate-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def genpykernels():
os.mkdir(tests_spec)
with open(os.path.join(tests_spec, "__init__.py"), "w") as f:
f.write(
"""# AUTO GENERATED ON {}
f"""# AUTO GENERATED ON {reproducible_datetime()}
# DO NOT EDIT BY HAND!
#
# To regenerate file, run
Expand All @@ -244,9 +244,7 @@ def genpykernels():

# fmt: off

""".format(
reproducible_datetime()
)
"""
)

with open(
Expand Down Expand Up @@ -323,7 +321,7 @@ def genspectests(specdict):
"w",
) as f:
f.write(
"""# AUTO GENERATED ON {}
f"""# AUTO GENERATED ON {reproducible_datetime()}
# DO NOT EDIT BY HAND!
#
# To regenerate file, run
Expand All @@ -333,9 +331,7 @@ def genspectests(specdict):

# fmt: off

""".format(
reproducible_datetime()
)
"""
)
f.write("import pytest\nimport kernels\n\n")
num = 1
Expand Down Expand Up @@ -437,7 +433,7 @@ def gencpukerneltests(specdict):
os.mkdir(tests_cpu_kernels)
with open(os.path.join(tests_cpu_kernels, "__init__.py"), "w") as f:
f.write(
"""# AUTO GENERATED ON {}
f"""# AUTO GENERATED ON {reproducible_datetime()}
# DO NOT EDIT BY HAND!
#
# To regenerate file, run
Expand All @@ -447,17 +443,15 @@ def gencpukerneltests(specdict):

# fmt: off

""".format(
reproducible_datetime()
)
"""
)

for spec in specdict.values():
with open(
os.path.join(tests_cpu_kernels, "test_cpu" + spec.name + ".py"), "w"
) as f:
f.write(
"""# AUTO GENERATED ON {}
f"""# AUTO GENERATED ON {reproducible_datetime()}
# DO NOT EDIT BY HAND!
#
# To regenerate file, run
Expand All @@ -467,9 +461,7 @@ def gencpukerneltests(specdict):

# fmt: off

""".format(
reproducible_datetime()
)
"""
)

f.write(
Expand Down Expand Up @@ -637,7 +629,7 @@ def gencudakerneltests(specdict):
os.mkdir(tests_cuda_kernels)
with open(os.path.join(tests_cuda_kernels, "__init__.py"), "w") as f:
f.write(
"""# AUTO GENERATED ON {}
f"""# AUTO GENERATED ON {reproducible_datetime()}
# DO NOT EDIT BY HAND!
#
# To regenerate file, run
Expand All @@ -647,9 +639,7 @@ def gencudakerneltests(specdict):

# fmt: off

""".format(
reproducible_datetime()
)
"""
)

for spec in specdict.values():
Expand All @@ -658,7 +648,7 @@ def gencudakerneltests(specdict):
os.path.join(tests_cuda_kernels, "test_cuda" + spec.name + ".py"), "w"
) as f:
f.write(
"""# AUTO GENERATED ON {}
f"""# AUTO GENERATED ON {reproducible_datetime()}
# DO NOT EDIT BY HAND!
#
# To regenerate file, run
Expand All @@ -668,9 +658,7 @@ def gencudakerneltests(specdict):

# fmt: off

""".format(
reproducible_datetime()
)
"""
)

f.write(
Expand Down
2 changes: 1 addition & 1 deletion src/awkward/_backends/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
numpy = Numpy.instance()


T = TypeVar("T", covariant=True)
T_co = TypeVar("T_co", covariant=True)
KernelKeyType: TypeAlias = Tuple[str, Unpack[Tuple[np.dtype, ...]]]
KernelType: TypeAlias = "Callable[..., KernelError | None]"

Expand Down
4 changes: 1 addition & 3 deletions src/awkward/_connect/numba/arrayview.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,7 @@ def repr_behavior(behavior):
class ArrayViewType(numba.types.IterableType, numba.types.Sized):
def __init__(self, type, behavior, fields):
super().__init__(
name="ak.ArrayView({}, {}, {})".format(
type.name, repr_behavior(behavior), repr(fields)
)
name=f"ak.ArrayView({type.name}, {repr_behavior(behavior)}, {fields!r})"
)
self.type = type
self.behavior = behavior
Expand Down
8 changes: 2 additions & 6 deletions src/awkward/_do.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,7 @@ def unique(layout: Content, axis=None):
negaxis = negaxis + depth
if not (0 < negaxis and negaxis <= depth):
raise AxisError(
"axis={} exceeds the depth of this array ({})".format(
axis, depth
)
f"axis={axis} exceeds the depth of this array ({depth})"
)

starts = ak.index.Index64.zeros(1, nplike=layout._backend.index_nplike)
Expand All @@ -185,9 +183,7 @@ def unique(layout: Content, axis=None):
return layout._unique(negaxis, starts, parents, 1)

raise AxisError(
"unique expects axis 'None' or '-1', got axis={} that is not supported yet".format(
axis
)
f"unique expects axis 'None' or '-1', got axis={axis} that is not supported yet"
)


Expand Down
10 changes: 2 additions & 8 deletions src/awkward/contents/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,7 @@ def getkey(layout):

else:
raise TypeError(
"form_key must be None, a string, or a callable, not {}".format(
type(form_key)
)
f"form_key must be None, a string, or a callable, not {type(form_key)}"
)

return self._form_with_key(getkey)
Expand Down Expand Up @@ -268,11 +266,7 @@ def _repr_extra(self, indent: str) -> list[str]:
out = []
if self._parameters is not None:
for k, v in self._parameters.items():
out.append(
"\n{}<parameter name={}>{}</parameter>".format(
indent, repr(k), repr(v)
)
)
out.append(f"\n{indent}<parameter name={k!r}>{v!r}</parameter>")
return out

def maybe_to_NumpyArray(self):
Expand Down
4 changes: 1 addition & 3 deletions src/awkward/contents/indexedarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,9 +965,7 @@ def _validity_error(self, path):
errors="surrogateescape"
).lstrip("\n").lstrip("(")
message = error.str.decode(errors="surrogateescape")
return 'at {} ("{}"): {} at i={}{}'.format(
path, type(self), message, error.id, filename
)
return f'at {path} ("{type(self)}"): {message} at i={error.id}{filename}'

else:
return self._content._validity_error(path + ".content")
Expand Down
4 changes: 1 addition & 3 deletions src/awkward/contents/indexedoptionarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -1480,9 +1480,7 @@ def _validity_error(self, path):
errors="surrogateescape"
).lstrip("\n").lstrip("(")
message = error.str.decode(errors="surrogateescape")
return 'at {} ("{}"): {} at i={}{}'.format(
path, type(self), message, error.id, filename
)
return f'at {path} ("{type(self)}"): {message} at i={error.id}{filename}'

else:
return self._content._validity_error(path + ".content")
Expand Down
4 changes: 1 addition & 3 deletions src/awkward/contents/listarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -1357,9 +1357,7 @@ def _validity_error(self, path):
errors="surrogateescape"
).lstrip("\n").lstrip("(")
message = error.str.decode(errors="surrogateescape")
return 'at {} ("{}"): {} at i={}{}'.format(
path, type(self), message, error.id, filename
)
return f'at {path} ("{type(self)}"): {message} at i={error.id}{filename}'
else:
return self._content._validity_error(path + ".content")

Expand Down
8 changes: 2 additions & 6 deletions src/awkward/contents/listoffsetarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ def __init__(self, offsets, content, *, parameters=None):
)
if offsets.length is not unknown_length and offsets.length == 0:
raise ValueError(
"{} len(offsets) ({}) must be >= 1".format(
type(self).__name__, offsets.length
)
f"{type(self).__name__} len(offsets) ({offsets.length}) must be >= 1"
)

if parameters is not None and parameters.get("__array__") == "string":
Expand Down Expand Up @@ -1758,9 +1756,7 @@ def _validity_error(self, path):
errors="surrogateescape"
).lstrip("\n").lstrip("(")
message = error.str.decode(errors="surrogateescape")
return 'at {} ("{}"): {} at i={}{}'.format(
path, type(self), message, error.id, filename
)
return f'at {path} ("{type(self)}"): {message} at i={error.id}{filename}'
else:
return self._content._validity_error(path + ".content")

Expand Down
4 changes: 1 addition & 3 deletions src/awkward/contents/unionarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -1400,9 +1400,7 @@ def _validity_error(self, path):
errors="surrogateescape"
).lstrip("\n").lstrip("(")
message = error.str.decode(errors="surrogateescape")
return 'at {} ("{}"): {} at i={}{}'.format(
path, type(self), message, error.id, filename
)
return f'at {path} ("{type(self)}"): {message} at i={error.id}{filename}'

# Check triangular pairs (i, j) are not mergeable
for i, content_i in enumerate(self._contents):
Expand Down
8 changes: 2 additions & 6 deletions src/awkward/forms/bitmaskedform.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ def __init__(
):
if not isinstance(mask, str):
raise TypeError(
"{} 'mask' must be of type str, not {}".format(
type(self).__name__, repr(mask)
)
f"{type(self).__name__} 'mask' must be of type str, not {mask!r}"
)
if not isinstance(content, Form):
raise TypeError(
Expand All @@ -40,9 +38,7 @@ def __init__(
)
if not isinstance(lsb_order, bool):
raise TypeError(
"{} 'lsb_order' must be bool, not {}".format(
type(self).__name__, repr(lsb_order)
)
f"{type(self).__name__} 'lsb_order' must be bool, not {lsb_order!r}"
)

self._mask = mask
Expand Down
4 changes: 1 addition & 3 deletions src/awkward/forms/bytemaskedform.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ def __init__(
):
if not isinstance(mask, str):
raise TypeError(
"{} 'mask' must be of type str, not {}".format(
type(self).__name__, repr(mask)
)
f"{type(self).__name__} 'mask' must be of type str, not {mask!r}"
)
if not isinstance(content, Form):
raise TypeError(
Expand Down
4 changes: 1 addition & 3 deletions src/awkward/forms/indexedform.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ def __init__(
):
if not isinstance(index, str):
raise TypeError(
"{} 'index' must be of type str, not {}".format(
type(self).__name__, repr(index)
)
f"{type(self).__name__} 'index' must be of type str, not {index!r}"
)
if not isinstance(content, Form):
raise TypeError(
Expand Down
4 changes: 1 addition & 3 deletions src/awkward/forms/indexedoptionform.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ def __init__(
):
if not isinstance(index, str):
raise TypeError(
"{} 'index' must be of type str, not {}".format(
type(self).__name__, repr(index)
)
f"{type(self).__name__} 'index' must be of type str, not {index!r}"
)
if not isinstance(content, Form):
raise TypeError(
Expand Down
12 changes: 3 additions & 9 deletions src/awkward/forms/recordform.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ def __init__(
)
if fields is not None and not isinstance(fields, Iterable):
raise TypeError(
"{} 'fields' must be iterable, not {}".format(
type(self).__name__, repr(contents)
)
f"{type(self).__name__} 'fields' must be iterable, not {contents!r}"
)

self._fields = None if fields is None else list(fields)
Expand Down Expand Up @@ -99,9 +97,7 @@ def index_to_field(self, index):
return self._fields[index]
else:
raise IndexError(
"no index {} in record with {} fields".format(
index, len(self._contents)
)
f"no index {index} in record with {len(self._contents)} fields"
)

def field_to_index(self, field):
Expand All @@ -121,9 +117,7 @@ def field_to_index(self, field):
else:
return i
raise FieldNotFoundError(
"no field {} in record with {} fields".format(
repr(field), len(self._contents)
)
f"no field {field!r} in record with {len(self._contents)} fields"
)

def has_field(self, field):
Expand Down
Loading