Skip to content

Commit 2d839d0

Browse files
committed
Deprecate Python 3.9 and fix ruff upgrade issues
1 parent 5aba313 commit 2d839d0

File tree

10 files changed

+49
-39
lines changed

10 files changed

+49
-39
lines changed

.github/workflows/test_castep_outputs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
- name: Install vermin
2929
run: python -m pip install vermin
3030
- name: Run Vermin
31-
run: vermin -t=3.9- --lint --no-parse-comments castep_outputs
31+
run: vermin -t=3.10- --lint --no-parse-comments castep_outputs
3232

3333
build:
3434
runs-on: ubuntu-latest
@@ -37,7 +37,7 @@ jobs:
3737
pull-requests: write
3838
strategy:
3939
matrix:
40-
python-version: ["3.9", "3.10", "3.11", "3.12"]
40+
python-version: ["3.10", "3.11", "3.12"]
4141

4242
steps:
4343
- uses: actions/checkout@v4

castep_outputs/bin_parsers/cst_esp_file_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def parse_cst_esp_file(cst_esp_file: BinaryIO) -> ESPData:
3939
accum = {"esp": []}
4040

4141
reader = binary_file_reader(cst_esp_file)
42-
for (key, typ), datum in zip(dtypes.items(), reader):
42+
for (key, typ), datum in zip(dtypes.items(), reader, strict=False):
4343
accum[key] = to_type(datum, typ)
4444

4545
prev_nx = None

castep_outputs/parsers/castep_file_parser.py

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from collections import defaultdict
1313
from collections.abc import Callable
1414
from enum import Flag, auto
15-
from typing import Any, TextIO, Union, cast
15+
from typing import Any, TextIO, cast
1616

1717
from ..utilities import castep_res as REs
1818
from ..utilities.castep_res import gen_table_re, get_numbers, labelled_floats
@@ -1683,7 +1683,11 @@ def _process_unit_cell(block: Block) -> CellInfo:
16831683
else:
16841684
prop.append(float(numbers[0]))
16851685

1686-
cell.update({name: val for val, name in zip(prop, ("volume", "density_amu", "density_g"))})
1686+
cell.update({name: val for val, name in zip(
1687+
prop,
1688+
("volume", "density_amu", "density_g"),
1689+
strict=False,
1690+
)})
16871691

16881692
return cell
16891693

@@ -1812,7 +1816,7 @@ def _process_initial_spins(block: Block) -> dict[AtomIndex, InitialSpin]:
18121816
ind = atreg_to_index(val)
18131817
fix_data_types(val, {"spin": float, "magmom": float})
18141818
val["fix"] = val["fix"] == "T"
1815-
accum[ind] = cast(dict[str, Union[float, bool]], val)
1819+
accum[ind] = cast(dict[str, float | bool], val)
18161820
return accum
18171821

18181822

@@ -2201,8 +2205,9 @@ def _process_dynamical_matrix(block: Block) -> tuple[tuple[complex, ...], ...]:
22012205
imag_part = [numbers[2:] for line in block if (numbers := get_numbers(line))]
22022206

22032207
return tuple(
2204-
tuple(complex(float(real), float(imag)) for real, imag in zip(real_row, imag_row))
2205-
for real_row, imag_row in zip(real_part, imag_part)
2208+
tuple(complex(float(real), float(imag))
2209+
for real, imag in zip(real_row, imag_row, strict=True))
2210+
for real_row, imag_row in zip(real_part, imag_part, strict=True)
22062211
)
22072212

22082213

@@ -2302,7 +2307,11 @@ def _process_dftd(block: Block) -> dict[str, Any]:
23022307
def _process_occupancies(block: Block) -> list[Occupancies]:
23032308
label = ("band", "eigenvalue", "occupancy")
23042309

2305-
accum = [dict(zip(label, numbers)) for line in block if (numbers := get_numbers(line))]
2310+
accum = [
2311+
dict(zip(label, numbers, strict=True))
2312+
for line in block
2313+
if (numbers := get_numbers(line))
2314+
]
23062315
for elem in accum:
23072316
fix_data_types(elem, {"band": int,
23082317
"eigenvalue": float,
@@ -2369,7 +2378,7 @@ def _process_phonon(block: Block, logger: Logger) -> list[QData]:
23692378
head, tail = char_line.split("|")
23702379
_, rep, *name, mul = head.split()
23712380
*vals, _ = tail.split()
2372-
char.append({"chars": tuple(zip(headers, map(int, vals))),
2381+
char.append({"chars": tuple(zip(headers, map(int, vals), strict=False)),
23732382
"mul": int(mul),
23742383
"rep": rep,
23752384
"name": name})
@@ -2429,9 +2438,13 @@ def _process_pair_params(block_in: Block) -> dict[str, dict[str, dict | str]]:
24292438
if lab not in accum[typ]:
24302439
accum[typ][lab] = {}
24312440

2432-
accum[typ][lab].update(zip(labels,
2433-
to_type(match["params"].split(),
2434-
float)))
2441+
accum[typ][lab].update(
2442+
zip(
2443+
labels,
2444+
to_type(match["params"].split(), float),
2445+
strict=True,
2446+
),
2447+
)
24352448

24362449
elif match := REs.PAIR_POT_RES["two_body_one_spec"].match(blk_line):
24372450
labels = ((match["spec"],),)
@@ -2454,7 +2467,7 @@ def _process_pair_params(block_in: Block) -> dict[str, dict[str, dict | str]]:
24542467

24552468
accum[typ][lab].update(zip(labels,
24562469
to_type(match["params"].split(),
2457-
float)))
2470+
float), strict=False))
24582471

24592472
# Globals
24602473
elif match := REs.PAIR_POT_RES["three_body_val"].match(line):
@@ -2479,7 +2492,7 @@ def _process_geom_table(block: Block) -> GeomTable:
24792492
fix_data_types(val, dict.fromkeys(("lambda", "fdelta", "enthalpy"), float))
24802493

24812494
key = normalise_string(val.pop("step"))
2482-
accum[key] = cast(dict[str, Union[bool, float]], val)
2495+
accum[key] = cast(dict[str, bool | float], val)
24832496

24842497
elif match := REs.GEOMOPT_TABLE_RE.match(line):
24852498
val = match.groupdict()
@@ -2488,7 +2501,7 @@ def _process_geom_table(block: Block) -> GeomTable:
24882501
val["converged"] = val["converged"] == "Yes"
24892502

24902503
key = normalise_key(val.pop("parameter"))
2491-
accum[key] = cast(dict[str, Union[bool, float]], val)
2504+
accum[key] = cast(dict[str, bool | float], val)
24922505

24932506
return accum
24942507

@@ -2523,7 +2536,7 @@ def _process_elastic_properties(block: Block) -> ElasticProperties:
25232536
for line in block:
25242537
if "::" in line:
25252538
key = line.split("::")[0]
2526-
val = cast(Union[ThreeVector, SixVector], to_type(get_numbers(line), float))
2539+
val = cast(ThreeVector | SixVector, to_type(get_numbers(line), float))
25272540

25282541
if len(val) == 1:
25292542
val = val[0]
@@ -2543,7 +2556,7 @@ def _process_elastic_properties(block: Block) -> ElasticProperties:
25432556
def _process_internal_constraints(block: TextIO) -> list[InternalConstraints]:
25442557

25452558
# Skip table headers
2546-
for _ in zip(range(3), block):
2559+
for _ in zip(range(3), block, strict=False):
25472560
pass
25482561

25492562
accum = []

castep_outputs/parsers/cell_param_file_parser.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from collections import Counter, defaultdict
88
from collections.abc import Callable, Sequence
99
from functools import partial
10-
from typing import Any, Literal, TextIO, TypedDict, Union
10+
from typing import Any, Literal, TextIO, TypedDict
1111

1212
import castep_outputs.utilities.castep_res as REs
1313

@@ -72,18 +72,15 @@ class XCDef(TypedDict):
7272
xc: dict[str, float]
7373

7474

75-
DevelElem = MaybeSequence[Union[str, float, dict[str, Union[str, float]]]]
76-
DevelBlock = dict[str, Union[DevelElem, dict[str, DevelElem]]]
77-
HubbardU = dict[Union[str, AtomIndex], Union[str, dict[str, float]]]
75+
DevelElem = MaybeSequence[str | float | dict[str, str | float]]
76+
DevelBlock = dict[str, DevelElem | dict[str, DevelElem]]
77+
HubbardU = dict[str | AtomIndex, str | dict[str, float]]
7878
CellParamData = dict[
79-
str, Union[str, float, tuple[float, str], dict[str, Any], HubbardU, DevelBlock, XCDef],
79+
str, str | float | tuple[float, str] | dict[str, Any] | HubbardU | DevelBlock | XCDef,
8080
]
8181
GeneralBlock = dict[
8282
str,
83-
Union[
84-
list[Union[str, float]],
85-
dict[str, MaybeSequence[float]],
86-
],
83+
list[str | float] | dict[str, MaybeSequence[float]],
8784
]
8885

8986

@@ -180,7 +177,7 @@ def _parse_pspot_string(string: str, *, debug: bool = False) -> PSPotStrInfo:
180177

181178
for proj in pspot["proj"].split(":"):
182179
if match := REs.PSPOT_PROJ_RE.match(proj):
183-
pdict = dict(zip(REs.PSPOT_PROJ_GROUPS, match.groups()))
180+
pdict = dict(zip(REs.PSPOT_PROJ_GROUPS, match.groups(), strict=True))
184181
else:
185182
raise ValueError("Invalid PSPot string")
186183

@@ -565,12 +562,12 @@ def _parse_general(block: Block) -> GeneralBlock:
565562
if REs.SPEC_PROP_RE.match(line):
566563
if isinstance(block_data["data"], list):
567564
block_data["data"] = {}
568-
typing.cast(dict[str, MaybeSequence[Union[float, str]]], block_data["data"])
565+
typing.cast(dict[str, MaybeSequence[float | str]], block_data["data"])
569566

570567
spec, val = line.strip().split(maxsplit=1)
571568
val = to_type(val, determine_type(val))
572569

573-
typing.cast(MaybeSequence[Union[float, str]], val)
570+
typing.cast(MaybeSequence[float | str], val)
574571

575572
block_data["data"][spec] = val
576573

castep_outputs/parsers/parse_fmt_files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def _parse_kpt_info(
9393
words = line.split()
9494
qpt = to_type(words[0:3], int)
9595
val = to_type(words[3:], float)
96-
stack_dict(qdata, {"q": qpt, **dict(zip(prop, val))})
96+
stack_dict(qdata, {"q": qpt, **dict(zip(prop, val, strict=False))})
9797

9898
return qdata
9999

castep_outputs/parsers/tddft_file_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from __future__ import annotations
33

44
import re
5-
from typing import Literal, TextIO, TypedDict, Union
5+
from typing import Literal, TextIO, TypedDict
66

77
from ..utilities import castep_res as REs
88
from ..utilities.castep_res import get_numbers, labelled_floats
@@ -12,7 +12,7 @@
1212
from .parse_utilities import parse_regular_header
1313

1414
#: Overlap type
15-
TDDFTOverlap = dict[Union[tuple[int, int], Literal["total"]], float]
15+
TDDFTOverlap = dict[tuple[int, int] | Literal["total"], float]
1616

1717

1818
class TDDFTSpectroData(TypedDict):

castep_outputs/utilities/castep_res.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from .constants import FST_D, MINIMISERS, SHELLS, SND_D
1111

1212
#: Valid input where patterns are wanted.
13-
Pattern = Union[str, re.Pattern]
13+
Pattern = str | re.Pattern
1414

1515

1616
def get_numbers(line: str) -> list[str]:

castep_outputs/utilities/datatypes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from __future__ import annotations
33

44
from collections.abc import Callable, Sequence
5-
from typing import Any, Literal, TextIO, TypedDict, TypeVar, Union
5+
from typing import Any, Literal, TextIO, TypedDict, TypeVar
66

77
T = TypeVar("T")
88

@@ -11,7 +11,7 @@
1111

1212
# General types
1313

14-
MaybeSequence = Union[Sequence[T], T]
14+
MaybeSequence = Sequence[T] | T
1515

1616
#: CASTEP atom keys.
1717
AtomIndex = tuple[str, int]

castep_outputs/utilities/dumpers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
import json
55
import pprint
6+
from collections.abc import Callable
67
from contextlib import suppress
7-
from typing import Any, Callable, TextIO
8+
from typing import Any, TextIO
89

910
_YAML_TYPE = None
1011

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
66
name = "castep_outputs"
77
authors = [{name = "Jacob Wilkins", email = "[email protected]"}]
88
dynamic = ["version"]
9-
requires-python = ">= 3.9"
9+
requires-python = ">= 3.10"
1010
readme = "README.rst"
1111
description = "A package for extracting information from castep outputs"
1212
keywords = ["castep", "dft", "parser"]
@@ -50,7 +50,6 @@ version = {attr = "castep_outputs.__version__"}
5050
[tool.ruff]
5151
line-length = 100
5252
indent-width = 4
53-
target-version = "py39"
5453

5554
# Exclude a variety of commonly ignored directories.
5655
extend-exclude = [

0 commit comments

Comments
 (0)