From 9ed7bb8d02100dc5f7f6412bb7aff5b76090022c Mon Sep 17 00:00:00 2001 From: Matthew Filipovich <42307495+MatthewFilipovich@users.noreply.github.com> Date: Tue, 13 Jan 2026 14:36:34 +0000 Subject: [PATCH] Update ruff lint rules --- examples/free_particle_and_dipole_interaction.py | 12 +++++++++--- pyproject.toml | 4 ++++ src/pycharge/charge.py | 2 +- src/pycharge/functional/functional.py | 3 ++- src/pycharge/potentials_and_fields.py | 3 ++- src/pycharge/simulate.py | 2 +- src/pycharge/sources.py | 2 +- src/pycharge/types.py | 3 ++- tests/test_functional.py | 6 +----- 9 files changed, 23 insertions(+), 14 deletions(-) diff --git a/examples/free_particle_and_dipole_interaction.py b/examples/free_particle_and_dipole_interaction.py index 3851e1c..6602c64 100644 --- a/examples/free_particle_and_dipole_interaction.py +++ b/examples/free_particle_and_dipole_interaction.py @@ -116,9 +116,15 @@ def plot_z_position(ax, times, z_pos, color, title, vline_time=None): ts_fs = ts * 1e15 # Time in femtoseconds # Create titles with charge and position information -d1_title = f"Dipole Charge 1 (q={-q_dipole / e:.0f}e)\n(x={dipole_origin[0] * 1e9:.1f} nm, y={dipole_origin[1] * 1e9:.1f} nm)" -d2_title = f"Dipole Charge 2 (q={q_dipole / e:.0f}e)\n(x={dipole_origin[0] * 1e9:.1f} nm, y={dipole_origin[1] * 1e9:.1f} nm)" -p_title = f"Free Particle (q={q_particle / e:.0f}e)\n(x={particle_position[0] * 1e9:.1f} nm, y={particle_position[1] * 1e9:.1f} nm)" + + +def charge_title(label: str, q: float, pos: list) -> str: + return f"{label} (q={q / e:.0f}e)\n(x={pos[0] * 1e9:.1f} nm, y={pos[1] * 1e9:.1f} nm)" + + +d1_title = charge_title("Dipole Charge 1", -q_dipole, dipole_origin) +d2_title = charge_title("Dipole Charge 2", q_dipole, dipole_origin) +p_title = charge_title("Free Particle", q_particle, particle_position) plot_z_position(axes[0], ts_fs, d1_z, "C0", d1_title) plot_z_position(axes[1], ts_fs, d2_z, "C1", d2_title) diff --git a/pyproject.toml b/pyproject.toml index e09beb3..a3321da 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -63,6 +63,10 @@ where = ["src"] [tool.ruff] line-length = 110 +[tool.ruff.lint] +select = ["E", "F", "I", "UP", "B", "SIM", "C4"] +ignore = ["B905"] + [tool.coverage.report] omit = ["tests/*"] exclude_lines = [ diff --git a/src/pycharge/charge.py b/src/pycharge/charge.py index 12d007c..55a21fc 100644 --- a/src/pycharge/charge.py +++ b/src/pycharge/charge.py @@ -1,7 +1,7 @@ """Point charge representation and solver configuration for electromagnetic simulations.""" +from collections.abc import Callable from dataclasses import dataclass, field -from typing import Callable from scipy.constants import e diff --git a/src/pycharge/functional/functional.py b/src/pycharge/functional/functional.py index e756a12..ecf0367 100644 --- a/src/pycharge/functional/functional.py +++ b/src/pycharge/functional/functional.py @@ -2,7 +2,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Callable +from collections.abc import Callable +from typing import TYPE_CHECKING import jax import jax.numpy as jnp diff --git a/src/pycharge/potentials_and_fields.py b/src/pycharge/potentials_and_fields.py index d4949bf..3597fc2 100644 --- a/src/pycharge/potentials_and_fields.py +++ b/src/pycharge/potentials_and_fields.py @@ -1,6 +1,7 @@ """Liénard-Wiechert potentials and electromagnetic fields from moving point charges.""" -from typing import Callable, Iterable, NamedTuple +from collections.abc import Callable, Iterable +from typing import NamedTuple import jax import jax.numpy as jnp diff --git a/src/pycharge/simulate.py b/src/pycharge/simulate.py index 181c29b..2ae1009 100644 --- a/src/pycharge/simulate.py +++ b/src/pycharge/simulate.py @@ -1,7 +1,7 @@ """Time-stepping simulation of interacting electromagnetic sources.""" +from collections.abc import Callable, Sequence from dataclasses import replace -from typing import Callable, Sequence import jax import jax.numpy as jnp diff --git a/src/pycharge/sources.py b/src/pycharge/sources.py index 1c2cc69..e04af0d 100644 --- a/src/pycharge/sources.py +++ b/src/pycharge/sources.py @@ -1,7 +1,7 @@ """Defines electromagnetic sources used in simulations.""" +from collections.abc import Callable, Sequence from dataclasses import dataclass -from typing import Callable, Sequence import jax.numpy as jnp from scipy.constants import c, e, epsilon_0, m_e diff --git a/src/pycharge/types.py b/src/pycharge/types.py index d16705d..afdc685 100644 --- a/src/pycharge/types.py +++ b/src/pycharge/types.py @@ -1,6 +1,7 @@ """Type aliases for scalar values and 3D vectors.""" -from typing import Sequence, TypeAlias +from collections.abc import Sequence +from typing import TypeAlias from jax.typing import ArrayLike diff --git a/tests/test_functional.py b/tests/test_functional.py index d406d6d..e0b3c3b 100644 --- a/tests/test_functional.py +++ b/tests/test_functional.py @@ -65,11 +65,7 @@ def test_source_time_moving(t_val): t_switch = R / v0 # where the physical branch switches t = jnp.array(t_val) - if t_val <= t_switch: # Branch: R - v0 * tr >= 0 → tr = (c * t - R) / (c - v0) - expected_tr = (c * t - R) / (c - v0) - else: # Branch: R - v0 * tr < 0 → tr = (c * t + R) / (c + v0) - expected_tr = (c * t + R) / (c + v0) - + expected_tr = (c * t - R) / (c - v0) if t_val <= t_switch else (c * t + R) / (c + v0) tr = emission_time(r, t, charge) print(tr) assert jnp.allclose(tr, expected_tr)