Skip to content

Commit

Permalink
Removed the requirement for a particular version of Python in pre-commit
Browse files Browse the repository at this point in the history
I've realised that this only works if you have that particular version of Python installed locally -- pre-commit doesn't download this for you.

This unacceptably raises the bar for making contributions -- folks shouldn't have to modify their global system just to offer a PR against Equinox.

Unfortunately this has meant that I've had to remove a couple of dependencies from the `additional_dependencies` list, as they don't support Python 3.13, which is what is sometimes selected.

(Alternatives considered:

- Install the specified version of Python as part of the pre-commit hook. This would be ideal. Unfortunately `pre-commit` passes the specified `language_version` to `python -m virtualenv` under the hood, and that doesn't seem to offer a way to do this.

- Based on the above: something with `uv`? Unfortunately `pre-commit` have also elected *not* to support `uv` (pre-commit/pre-commit#3131, pre-commit/pre-commit#3222), which would have done this automatically. Maybe we just need to wait until the folks at Astral write their own version of pre-commit as well!

- Specify a range of versions for Python, so that we use whatever the system Python is, as long as it is below 3.13. Unfortunately pre-commit doesn't seem to support this.

- Write our own local hook that does whatever we damn well please: `uv` to installs the right version of Python, downloads pyright, and run it. If this becomes problematic amongst the other repos then I may well do this.
)
  • Loading branch information
patrick-kidger committed Jan 5, 2025
1 parent fe4121d commit aec99a2
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 9 deletions.
4 changes: 0 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ repos:
rev: v1.1.379
hooks:
- id: pyright
# must match the Python version used in CI
language_version: python3.11
additional_dependencies:
[
beartype,
Expand All @@ -21,7 +19,5 @@ repos:
jaxtyping,
optax,
pytest,
tensorflow,
tf2onnx,
typing_extensions,
]
2 changes: 1 addition & 1 deletion equinox/_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def __instancecheck__(cls, value):


class EnumerationItem(Module):
_value: Int[Union[Array, np.ndarray], ""]
_value: Int[Union[Array, np.ndarray[Any, np.dtype[np.signedinteger]]], ""]
# Should have annotation `"type[Enumeration]"`, but this fails due to beartype bug
# #289.
_enumeration: Any = field(static=True)
Expand Down
4 changes: 2 additions & 2 deletions equinox/_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def is_inexact_array(element: Any) -> bool:
array.
"""
if isinstance(element, (np.ndarray, np.generic)):
return np.issubdtype(element.dtype, np.inexact)
return bool(np.issubdtype(element.dtype, np.inexact))
elif isinstance(element, jax.Array):
return jnp.issubdtype(element.dtype, jnp.inexact)
else:
Expand All @@ -51,7 +51,7 @@ def is_inexact_array_like(element: Any) -> bool:
if hasattr(element, "__jax_array__"):
element = element.__jax_array__()
if isinstance(element, (np.ndarray, np.generic)):
return np.issubdtype(element.dtype, np.inexact)
return bool(np.issubdtype(element.dtype, np.inexact))
elif isinstance(element, jax.Array):
return jnp.issubdtype(element.dtype, jnp.inexact)
else:
Expand Down
4 changes: 2 additions & 2 deletions equinox/internal/_onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def f(x, y):
```
"""
import jax.experimental.jax2tf as jax2tf
import tensorflow as tf
import tf2onnx
import tensorflow as tf # pyright: ignore[reportMissingImports]
import tf2onnx # pyright: ignore[reportMissingImports]

def _to_onnx(*args):
finalised_fn = finalise_fn(fn)
Expand Down

0 comments on commit aec99a2

Please sign in to comment.