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: cleanup mypy config #3853

Draft
wants to merge 8 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,12 @@ repos:
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
hooks:
- id: mypy
files: pybamm
additional_dependencies:
- numpy
- packaging
2 changes: 1 addition & 1 deletion pybamm/expression_tree/binary_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _preprocess_binary(
right = pybamm.Vector(right)

# Check both left and right are pybamm Symbols
if not (isinstance(left, pybamm.Symbol) and isinstance(right, pybamm.Symbol)):
if not (isinstance(left, pybamm.Symbol) and isinstance(right, pybamm.Symbol)): # type: ignore[redundant-expr]
raise NotImplementedError(
"""BinaryOperator not implemented for symbols of type {} and {}""".format(
type(left), type(right)
Expand Down
2 changes: 1 addition & 1 deletion pybamm/plotting/quick_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def __init__(
# Set colors, linestyles, figsize, axis limits
# call LoopList to make sure list index never runs out
if colors is None:
self.colors = LoopList(colors or ["r", "b", "k", "g", "m", "c"])
self.colors = LoopList(["r", "b", "k", "g", "m", "c"])
else:
self.colors = LoopList(colors)
self.linestyles = LoopList(linestyles or ["-", ":", "--", "-."])
Expand Down
17 changes: 9 additions & 8 deletions pybamm/solvers/idaklu_jax.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from __future__ import annotations

import pybamm
import numpy as np
import logging
import warnings
import numbers

from typing import Union
from typing import List

from functools import lru_cache

Expand Down Expand Up @@ -273,9 +274,9 @@ def f_isolated(*args, **kwargs):

def jax_value(
self,
t: np.ndarray = None,
inputs: Union[dict, None] = None,
output_variables: Union[List[str], None] = None,
t: np.ndarray | None = None,
inputs: dict | None = None,
output_variables: list[str] | None = None,
):
"""Helper function to compute the gradient of a jaxified expression

Expand Down Expand Up @@ -306,9 +307,9 @@ def jax_value(

def jax_grad(
self,
t: np.ndarray = None,
inputs: Union[dict, None] = None,
output_variables: Union[List[str], None] = None,
t: np.ndarray | None = None,
inputs: dict | None = None,
output_variables: list[str] | None = None,
):
"""Helper function to compute the gradient of a jaxified expression

Expand Down Expand Up @@ -489,7 +490,7 @@ def _jax_vjp_impl(
if t.ndim == 0 or (t.ndim == 1 and t.shape[0] == 1):
# scalar time input
logger.debug("scalar time")
y_dot = jnp.zeros_like(t)
y_dot: jax.Array | np.ndarray = jnp.zeros_like(t)
js = self._jaxify_solve(t, invar, *inputs)
if js.ndim == 0:
js = jnp.array([js])
Expand Down
10 changes: 9 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,21 @@ concurrency = ["multiprocessing"]

[tool.repo-review]
ignore = [
"PP003" # list wheel as a build-dep
"PP003", # list wheel as a build-dep
"PC160", # codespell
"PC180", # prettier

]

[tool.mypy]
ignore_missing_imports = true
allow_redefinition = true
disable_error_code = ["call-overload", "operator"]
enable_error_code = [
"ignore-without-code",
"truthy-bool",
"redundant-expr",
]

[[tool.mypy.overrides]]
module = [
Expand Down