Skip to content

Commit

Permalink
More linting
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondEhlers committed Feb 16, 2024
1 parent ccc6c10 commit 27c977f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
7 changes: 4 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ repos:
# Same with ruamel.yaml
additional_dependencies:
- pytest
- "attrs>=19.3.0"
- "ruamel.yaml>=0.16.10"
- "numpy>=1.21"
- "attrs>=21.2.0"
- "numpy>=1.23.4"
- "ruamel.yaml>=0.17.10"
- "boost-histogram>=1.4"

- repo: https://github.com/codespell-project/codespell
rev: "v2.2.6"
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ module = "pachyderm.*"
disallow_untyped_defs = true
disallow_incomplete_defs = true

[[tool.mypy.overrides]]
module = ["ROOT", "numba", "nox"]
ignore_missing_imports = true


[tool.ruff]
src = ["src"]
Expand Down
10 changes: 5 additions & 5 deletions src/pachyderm/binned_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
# If only supporting 3.7+, we can add `from __future__ import annotations` and just use the more detailed definition
if TYPE_CHECKING:
AxesTupleAttribute = attrs.Attribute["AxesTuple"]
NumpyAttribute = attrs.Attribute[npt.NDArray[Any]]
NPAttribute = attrs.Attribute[npt.NDArray[Any]]
else:
AxesTupleAttribute = attrs.Attribute
NumpyAttribute = attrs.Attribute
NPAttribute = attrs.Attribute


@attrs.frozen
Expand Down Expand Up @@ -469,7 +469,7 @@ def _validate_axes(instance: BinnedData, attribute: AxesTupleAttribute, value: A
raise ValueError(_msg)


def _validate_arrays(instance: BinnedData, attribute: NumpyAttribute, value: npt.NDArray[Any]) -> None:
def _validate_arrays(instance: BinnedData, attribute: NPAttribute, value: npt.NDArray[Any]) -> None:
expected_length = _array_length_from_axes(instance.axes)
if value.size != expected_length:
_msg = (
Expand Down Expand Up @@ -1261,9 +1261,9 @@ def _apply_rebin(

# Only use numba if available
f = _sum_values_for_rebin_numba if _sum_values_for_rebin_numba is not None else _sum_values_for_rebin
return f(
return f( # type: ignore[no-any-return]
n_bins_new_axis=n_bins_new_axis,
values=values, # type: ignore[no-any-return]
values=values,
run_starts=run_starts,
run_values=run_values,
run_lengths=run_lengths,
Expand Down
8 changes: 5 additions & 3 deletions src/pachyderm/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,11 +566,13 @@ def __add__(self: _T, other: _T) -> _T:
new += other
return new

def __radd__(self: _T, other: _T) -> _T:
def __radd__(self: _T, other: int | _T) -> _T:
"""For use with sum(...)."""
if other == 0:
return self
else:
# Help out mypy
assert not isinstance(other, int)
return self + other

def __iadd__(self: _T, other: _T) -> _T:
Expand Down Expand Up @@ -642,7 +644,7 @@ def __imul__(self: _T, other: Union[_T, float]) -> _T:
self.errors_squared *= other ** 2
# Scale stats accordingly. We can only preserve the stats if using a scalar (according to ROOT).
if np.isscalar(other):
self._scale_stats(scale_factor=other)
self._scale_stats(scale_factor=other) # type: ignore[arg-type]
else:
self._recalculate_stats()
else:
Expand Down Expand Up @@ -681,7 +683,7 @@ def __itruediv__(self: _T, other: Union[_T, float]) -> _T:
self *= 1.0 / other
# Scale stats accordingly. We can only preserve the stats if using a scalar (according to ROOT).
if np.isscalar(other):
self._scale_stats(scale_factor=1.0 / other)
self._scale_stats(scale_factor=1.0 / other) # type: ignore[operator,arg-type]
else:
self._recalculate_stats()
else:
Expand Down

0 comments on commit 27c977f

Please sign in to comment.