Skip to content

Commit

Permalink
feat: bump python version to 3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfikl committed Sep 1, 2024
1 parent c226ea1 commit 72a3e50
Show file tree
Hide file tree
Showing 19 changed files with 45 additions and 47 deletions.
4 changes: 2 additions & 2 deletions examples/mittag-leffler-function.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
with figure("mittag-leffler-figure10") as fig:
ax = fig.gca()

for alpha, value in zip(E_alpha, E_alpha_value):
for alpha, value in zip(E_alpha, E_alpha_value, strict=True):
ax.plot(x, value, label=rf"$\alpha = {alpha:.2f}$")

ax.set_xlim([0.0, 5.0])
Expand All @@ -68,7 +68,7 @@
with figure("mittag-leffler-figure11") as fig:
ax = fig.gca()

for beta, value in zip(E_beta, E_beta_value):
for beta, value in zip(E_beta, E_beta_value, strict=True):
ax.plot(x, value, label=rf"$\beta = {beta:.2f}$")

ax.set_xlim([0.0, 5.0])
Expand Down
8 changes: 3 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ maintainers = [
authors = [
{ name = "Alexandru Fikl", email = "alexfikl@gmail.com" },
]
requires-python = ">=3.9"
requires-python = ">=3.10"
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
Expand All @@ -32,7 +32,6 @@ classifiers = [
"Natural Language :: English",
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
Expand All @@ -43,7 +42,6 @@ dependencies = [
"numpy>=1.17",
"rich>=13",
"scipy>=1.7",
"typing-extensions; python_version<'3.10'",
]
optional-dependencies.dev = [
"differint @ git+https://github.com/differint/differint.git#egg=differint",
Expand Down Expand Up @@ -86,7 +84,7 @@ packages = [
]

[tool.ruff]
target-version = "py38"
target-version = "py310"
line-length = 88

preview = true
Expand Down Expand Up @@ -157,7 +155,7 @@ addopts = [

[tool.mypy]
strict = true
python_version = "3.9"
python_version = "3.10"
hide_error_codes = false
warn_unused_ignores = true
local_partial_types = true
Expand Down
2 changes: 1 addition & 1 deletion src/pycaputo/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _hairer_norm(x: Array, *, p: int | float | str = 2) -> float:

from numbers import Number

if isinstance(p, (int, float, Number)):
if isinstance(p, int | float | Number):
return float((np.sum(x**p) / x.size) ** (1.0 / p))

raise ValueError(f"Unknown norm order: {p!r}")
Expand Down
3 changes: 2 additions & 1 deletion src/pycaputo/fode/product_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

from __future__ import annotations

from collections.abc import Iterator
from dataclasses import dataclass
from typing import Any, Iterator, NamedTuple
from typing import Any, NamedTuple

import numpy as np

Expand Down
2 changes: 1 addition & 1 deletion src/pycaputo/generating_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from __future__ import annotations

from typing import Iterator
from collections.abc import Iterator

import numpy as np

Expand Down
5 changes: 3 additions & 2 deletions src/pycaputo/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

from __future__ import annotations

from collections.abc import Callable
from dataclasses import dataclass, replace
from functools import cached_property
from typing import Any, Callable
from typing import Any

import numpy as np

Expand Down Expand Up @@ -44,7 +45,7 @@ def size(self) -> int:
@property
def shape(self) -> tuple[int, ...]:
"""The shape of the points array in the set."""
return self.x.shape
return self.x.shape # type: ignore[no-any-return]

@cached_property
def dx(self) -> Array:
Expand Down
3 changes: 2 additions & 1 deletion src/pycaputo/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
from __future__ import annotations

from abc import ABC, abstractmethod
from collections.abc import Iterable
from dataclasses import dataclass, field, fields
from typing import Any, Generic, Iterable, TypeVar
from typing import Any, Generic, TypeVar

import numpy as np

Expand Down
3 changes: 2 additions & 1 deletion src/pycaputo/integrate_fire/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
from __future__ import annotations

from abc import ABC, abstractmethod
from collections.abc import Iterator
from dataclasses import dataclass
from functools import cached_property
from typing import Any, Iterator, NamedTuple, TypeVar
from typing import Any, NamedTuple, TypeVar

import numpy as np

Expand Down
3 changes: 2 additions & 1 deletion src/pycaputo/integrate_fire/lif.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

from __future__ import annotations

from collections.abc import Callable
from dataclasses import dataclass
from typing import Callable, NamedTuple, overload
from typing import NamedTuple, overload

import numpy as np

Expand Down
3 changes: 2 additions & 1 deletion src/pycaputo/interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
from __future__ import annotations

import math
from collections.abc import Iterator
from dataclasses import dataclass
from functools import cached_property
from typing import Any, Iterator
from typing import Any

import numpy as np

Expand Down
2 changes: 1 addition & 1 deletion src/pycaputo/jacobi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from __future__ import annotations

from typing import Iterator
from collections.abc import Iterator

import numpy as np

Expand Down
2 changes: 1 addition & 1 deletion src/pycaputo/lagrange.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from __future__ import annotations

from collections.abc import Iterator
from dataclasses import dataclass
from typing import Iterator

import numpy as np

Expand Down
2 changes: 1 addition & 1 deletion src/pycaputo/quadrature/riemann_liouville.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ def xi(self) -> Array:
"""
from numpy.polynomial.legendre import leggauss

xi, _ = leggauss(self.npoints) # type: ignore[no-untyped-call]
xi, _ = leggauss(self.npoints)
return np.array(xi + 1.0) / 2.0


Expand Down
3 changes: 2 additions & 1 deletion src/pycaputo/stepping.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
from __future__ import annotations

from abc import ABC, abstractmethod
from collections.abc import Iterable, Iterator
from dataclasses import dataclass
from functools import cached_property, singledispatch
from typing import TYPE_CHECKING, Any, Generic, Iterable, Iterator
from typing import TYPE_CHECKING, Any, Generic

import numpy as np
from scipy.special import gamma
Expand Down
17 changes: 5 additions & 12 deletions src/pycaputo/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,19 @@
from __future__ import annotations

import pathlib
import sys
from dataclasses import Field
from typing import (
TYPE_CHECKING,
Any,
ClassVar,
ParamSpec,
Protocol,
TypeVar,
Union,
runtime_checkable,
)

import numpy as np

if sys.version_info >= (3, 10):
from typing import ParamSpec
else:
from typing_extensions import ParamSpec


# {{{ TypeVars

# NOTE: sphinx doesn't seem to render this correctly at the moment, so it's
Expand All @@ -35,7 +28,7 @@
R = TypeVar("R")
"""A generic invariant :class:`typing.TypeVar`."""

PathLike = Union[pathlib.Path, str]
PathLike = pathlib.Path | str
"""A union of types supported as paths."""


Expand All @@ -47,11 +40,11 @@

if TYPE_CHECKING:
Array = np.ndarray[Any, Any]
Scalar = Union[np.number[Any], Array]
Scalar = np.number[Any] | Array
else:
Array = np.ndarray
"""Array type alias for :class:`numpy.ndarray`."""
Scalar = Union[np.number, Array]
Scalar = np.number | Array
"""Scalar type alias (generally a value convertible to a :class:`float`)."""


Expand Down Expand Up @@ -102,7 +95,7 @@ def __call__(self, x: Array, /, d: int = 0) -> Array:
"""


ArrayOrScalarFunction = Union[Array, ScalarFunction, DifferentiableScalarFunction]
ArrayOrScalarFunction = Array | ScalarFunction | DifferentiableScalarFunction
"""A union of scalar functions."""


Expand Down
17 changes: 6 additions & 11 deletions src/pycaputo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,18 @@
from __future__ import annotations

import pathlib
import sys
import time
from collections.abc import Callable, Iterable, Iterator
from contextlib import contextmanager, suppress
from dataclasses import dataclass, field, is_dataclass
from types import TracebackType
from typing import Any, Callable, Iterable, Iterator, Literal, NamedTuple
from typing import Any, Concatenate, Literal, NamedTuple

import numpy as np

from pycaputo.logging import get_logger
from pycaputo.typing import Array, DataclassInstance, P, PathLike, R, T

if sys.version_info >= (3, 10):
from typing import Concatenate
else:
from typing_extensions import Concatenate

logger = get_logger(__name__)


Expand Down Expand Up @@ -64,7 +59,7 @@ def from_data(

def add_data_points(self, h: Array, error: Array) -> None:
"""Add multiple data points using :meth:`add_data_point`."""
for h_i, e_i in zip(h, error):
for h_i, e_i in zip(h, error, strict=True):
self.add_data_point(h_i, e_i)

def add_data_point(self, h: Any, error: Any) -> None:
Expand Down Expand Up @@ -175,7 +170,7 @@ def stringify_eoc(*eocs: EOCRecorder) -> str:
f"{error[i]:.6e}",
"---" if i == 0 else f"{order[i - 1, 1]:.3f}",
)
for (_, error), order in zip(histories, orders)
for (_, error), order in zip(histories, orders, strict=True)
])
lines.append((f"{h[i]:.3e}", *values))

Expand All @@ -196,7 +191,7 @@ def stringify_eoc(*eocs: EOCRecorder) -> str:
formats = ["{:%s}" % w for w in widths] # noqa: UP031

return "\n".join([
" | ".join(fmt.format(value) for fmt, value in zip(formats, line))
" | ".join(fmt.format(value) for fmt, value in zip(formats, line, strict=True))
for line in lines
])

Expand Down Expand Up @@ -230,7 +225,7 @@ def visualize_eoc(
# {{{ plot eocs

line = None
for eoc, marker in zip(eocs, markers):
for eoc, marker in zip(eocs, markers, strict=True):
h, error = np.array(eoc.history).T
ax.loglog(h, error, marker=marker, label=eoc.name)

Expand Down
3 changes: 2 additions & 1 deletion tests/test_fode_caputo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
from __future__ import annotations

import pathlib
from collections.abc import Callable
from dataclasses import replace
from functools import partial
from typing import Any, Callable
from typing import Any

import numpy as np
import numpy.linalg as la
Expand Down
8 changes: 6 additions & 2 deletions tests/test_integrate_fire.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ def func(ad_ex: AdExModel, tspike: float, yprev: Array, r: Array) -> float:
ad_ex = AdExModel(param)

y0 = np.array([rng.uniform(param.v_reset, param.v_peak) - 10, rng.uniform()])
r = np.array([dt**a / gamma(1 - a) * yi for a, yi in zip(alpha, y0)])
r = np.array([
dt**a / gamma(1 - a) * yi for a, yi in zip(alpha, y0, strict=True)
])

method = CaputoAdExIntegrateFireL1Model(
derivative_order=alpha,
Expand Down Expand Up @@ -298,7 +300,9 @@ def test_ad_ex_solve() -> None:
)

h = np.array([gamma(2 - a) * dt**a for a in alpha])
r = np.array([dt**a / gamma(1 - a) * yi for a, yi in zip(alpha, y0)])
r = np.array([
dt**a / gamma(1 - a) * yi for a, yi in zip(alpha, y0, strict=True)
])

y = method.solve(t, y0, h, r)
error = y - h * ad_ex.source(t, y) - r
Expand Down
2 changes: 1 addition & 1 deletion tests/test_mittag_leffler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from __future__ import annotations

import pathlib
from collections.abc import Callable
from functools import partial
from typing import Callable

import numpy as np
import pytest
Expand Down

0 comments on commit 72a3e50

Please sign in to comment.