Skip to content

Commit 1c1fc14

Browse files
Always use zip(strict=True) (#414)
* Always use zip(strict=True) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update to Python 3.10 as minimum * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * be more strict --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 9edbd88 commit 1c1fc14

File tree

19 files changed

+135
-150
lines changed

19 files changed

+135
-150
lines changed

.ci_support/release.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def get_setup_version_and_pattern(setup_content):
1515
version_lst.append(dep.split("==")[1])
1616
depend_lst.append(dep.split("==")[0])
1717

18-
version_high_dict = {d: v for d, v in zip(depend_lst, version_lst)}
18+
version_high_dict = {d: v for d, v in zip(depend_lst, version_lst, strict=True)}
1919
return version_high_dict
2020

2121

@@ -30,7 +30,7 @@ def get_env_version(env_content):
3030
if len(lst) == 2:
3131
depend_lst.append(lst[0])
3232
version_lst.append(lst[1])
33-
return {d: v for d, v in zip(depend_lst, version_lst)}
33+
return {d: v for d, v in zip(depend_lst, version_lst, strict=True)}
3434

3535

3636
def update_dependencies(setup_content, version_low_dict, version_high_dict):

.github/workflows/pipeline.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ jobs:
149149
- name: Setup Mambaforge
150150
uses: conda-incubator/setup-miniconda@v3
151151
with:
152-
python-version: '3.9'
152+
python-version: '3.10'
153153
miniforge-version: latest
154154
condarc-file: .condarc
155155
environment-file: .ci_support/environment-old.yml

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ authors = [
1111
readme = "README.md"
1212
license = { file = "LICENSE" }
1313
keywords = ["pyiron"]
14-
requires-python = ">=3.9, <3.14"
14+
requires-python = ">=3.10, <3.14"
1515
classifiers = [
1616
"Development Status :: 5 - Production/Stable",
1717
"Topic :: Scientific/Engineering :: Physics",
1818
"License :: OSI Approved :: BSD License",
1919
"Intended Audience :: Science/Research",
2020
"Operating System :: OS Independent",
21-
"Programming Language :: Python :: 3.9",
2221
"Programming Language :: Python :: 3.10",
2322
"Programming Language :: Python :: 3.11",
2423
"Programming Language :: Python :: 3.12",

structuretoolkit/analyse/distance.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
from typing import Optional
2-
31
import numpy as np
42
from ase.atoms import Atoms
53

64

75
def get_distances_array(
86
structure: Atoms,
9-
p1: Optional[np.ndarray] = None,
10-
p2: Optional[np.ndarray] = None,
7+
p1: np.ndarray | None = None,
8+
p2: np.ndarray | None = None,
119
mic: bool = True,
1210
vectors: bool = False,
1311
) -> np.ndarray:

structuretoolkit/analyse/dscribe.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
from typing import Optional
2-
31
import numpy as np
42
from ase.atoms import Atoms
53

64

75
def soap_descriptor_per_atom(
86
structure: Atoms,
9-
r_cut: Optional[float] = None,
10-
n_max: Optional[int] = None,
11-
l_max: Optional[int] = None,
12-
sigma: Optional[float] = 1.0,
7+
r_cut: float | None = None,
8+
n_max: int | None = None,
9+
l_max: int | None = None,
10+
sigma: float | None = 1.0,
1311
rbf: str = "gto",
14-
weighting: Optional[np.ndarray] = None,
12+
weighting: np.ndarray | None = None,
1513
average: str = "off",
1614
compression: dict = None,
17-
species: Optional[list] = None,
15+
species: list | None = None,
1816
periodic: bool = True,
1917
sparse: bool = False,
2018
dtype: str = "float64",
21-
centers: Optional[np.ndarray] = None,
19+
centers: np.ndarray | None = None,
2220
n_jobs: int = 1,
2321
only_physical_cores: bool = False,
2422
verbose: bool = False,

structuretoolkit/analyse/neighbors.py

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import itertools
55
import warnings
6-
from typing import Optional, Union
76

87
import numpy as np
98
from ase.atoms import Atoms
@@ -149,8 +148,8 @@ def copy(self) -> "Tree":
149148
def _reshape(
150149
self,
151150
value: np.ndarray,
152-
key: Optional[str] = None,
153-
ref_vector: Optional[np.ndarray] = None,
151+
key: str | None = None,
152+
ref_vector: np.ndarray | None = None,
154153
) -> np.ndarray:
155154
"""
156155
Reshape the given value based on the specified key and reference vector.
@@ -258,7 +257,7 @@ def norm_order(self, value: int) -> None:
258257
+ " with the correct norm_order value"
259258
)
260259

261-
def _get_max_length(self, ref_vector: Optional[np.ndarray] = None) -> int:
260+
def _get_max_length(self, ref_vector: np.ndarray | None = None) -> int:
262261
"""
263262
Get the maximum length of the reference vector.
264263
@@ -279,7 +278,7 @@ def _get_max_length(self, ref_vector: Optional[np.ndarray] = None) -> int:
279278
return max(len(dd[dd < np.inf]) for dd in ref_vector)
280279

281280
def _contract(
282-
self, value: np.ndarray, ref_vector: Optional[np.ndarray] = None
281+
self, value: np.ndarray, ref_vector: np.ndarray | None = None
283282
) -> np.ndarray:
284283
"""
285284
Contract the given value based on the specified reference vector.
@@ -295,7 +294,7 @@ def _contract(
295294
return value
296295
return [
297296
vv[: np.sum(dist < np.inf)]
298-
for vv, dist in zip(value, self.filled.distances)
297+
for vv, dist in zip(value, self.filled.distances, strict=True)
299298
]
300299

301300
def _allow_ragged_to_mode(self, new_bool: bool) -> str:
@@ -362,7 +361,7 @@ def _get_wrapped_positions(
362361
def _get_distances_and_indices(
363362
self,
364363
positions: np.ndarray,
365-
num_neighbors: Optional[int] = None,
364+
num_neighbors: int | None = None,
366365
cutoff_radius: float = np.inf,
367366
width_buffer: float = 1.2,
368367
) -> tuple[np.ndarray, np.ndarray]:
@@ -431,10 +430,10 @@ def numbers_of_neighbors(self) -> int:
431430
def _get_vectors(
432431
self,
433432
positions: np.ndarray,
434-
num_neighbors: Optional[int] = None,
433+
num_neighbors: int | None = None,
435434
cutoff_radius: float = np.inf,
436-
distances: Optional[np.ndarray] = None,
437-
indices: Optional[np.ndarray] = None,
435+
distances: np.ndarray | None = None,
436+
indices: np.ndarray | None = None,
438437
width_buffer: float = 1.2,
439438
) -> np.ndarray:
440439
"""
@@ -470,7 +469,7 @@ def _get_vectors(
470469

471470
def _estimate_num_neighbors(
472471
self,
473-
num_neighbors: Optional[int] = None,
472+
num_neighbors: int | None = None,
474473
cutoff_radius: float = np.inf,
475474
width_buffer: float = 1.2,
476475
) -> int:
@@ -515,7 +514,7 @@ def _estimate_num_neighbors(
515514

516515
def _estimate_width(
517516
self,
518-
num_neighbors: Optional[int] = None,
517+
num_neighbors: int | None = None,
519518
cutoff_radius: float = np.inf,
520519
width_buffer: float = 1.2,
521520
) -> float:
@@ -551,7 +550,7 @@ def _estimate_width(
551550
def get_neighborhood(
552551
self,
553552
positions: np.ndarray,
554-
num_neighbors: Optional[int] = None,
553+
num_neighbors: int | None = None,
555554
cutoff_radius: float = np.inf,
556555
width_buffer: float = 1.2,
557556
) -> "Tree":
@@ -647,7 +646,7 @@ def get_spherical_harmonics(
647646
l: np.ndarray,
648647
m: np.ndarray,
649648
cutoff_radius: float = np.inf,
650-
rotation: Optional[np.ndarray] = None,
649+
rotation: np.ndarray | None = None,
651650
) -> np.ndarray:
652651
"""
653652
Args:
@@ -868,8 +867,8 @@ def shells(self) -> np.ndarray:
868867

869868
def get_local_shells(
870869
self,
871-
mode: Optional[str] = None,
872-
tolerance: Optional[int] = None,
870+
mode: str | None = None,
871+
tolerance: int | None = None,
873872
cluster_by_distances: bool = False,
874873
cluster_by_vecs: bool = False,
875874
) -> np.ndarray:
@@ -947,8 +946,8 @@ def get_local_shells(
947946

948947
def get_global_shells(
949948
self,
950-
mode: Optional[str] = None,
951-
tolerance: Optional[int] = None,
949+
mode: str | None = None,
950+
tolerance: int | None = None,
952951
cluster_by_distances: bool = False,
953952
cluster_by_vecs: bool = False,
954953
) -> np.ndarray:
@@ -1008,7 +1007,7 @@ def get_global_shells(
10081007

10091008
def get_shell_matrix(
10101009
self,
1011-
chemical_pair: Optional[list[str]] = None,
1010+
chemical_pair: list[str] | None = None,
10121011
cluster_by_distances: bool = False,
10131012
cluster_by_vecs: bool = False,
10141013
):
@@ -1107,8 +1106,8 @@ def find_neighbors_by_vector(
11071106

11081107
def cluster_by_vecs(
11091108
self,
1110-
distance_threshold: Optional[float] = None,
1111-
n_clusters: Optional[int] = None,
1109+
distance_threshold: float | None = None,
1110+
n_clusters: int | None = None,
11121111
linkage: str = "complete",
11131112
metric: str = "euclidean",
11141113
):
@@ -1152,8 +1151,8 @@ def cluster_by_vecs(
11521151

11531152
def cluster_by_distances(
11541153
self,
1155-
distance_threshold: Optional[float] = None,
1156-
n_clusters: Optional[int] = None,
1154+
distance_threshold: float | None = None,
1155+
n_clusters: int | None = None,
11571156
linkage: str = "complete",
11581157
metric: str = "euclidean",
11591158
use_vecs: bool = False,
@@ -1225,7 +1224,7 @@ def reset_clusters(self, vecs: bool = True, distances: bool = True):
12251224

12261225
def cluster_analysis(
12271226
self, id_list: list, return_cluster_sizes: bool = False
1228-
) -> Union[dict[int, list[int]], tuple[dict[int, list[int]], list[int]]]:
1227+
) -> dict[int, list[int]] | tuple[dict[int, list[int]], list[int]]:
12291228
"""
12301229
Perform cluster analysis on a list of atom IDs.
12311230
@@ -1283,7 +1282,7 @@ def __probe_cluster(
12831282
def get_bonds(
12841283
self,
12851284
radius: float = np.inf,
1286-
max_shells: Optional[int] = None,
1285+
max_shells: int | None = None,
12871286
prec: float = 0.1,
12881287
) -> list[dict[str, list[list[int]]]]:
12891288
"""
@@ -1322,7 +1321,7 @@ def get_cluster(
13221321
el_list = self._ref_structure.get_chemical_symbols()
13231322

13241323
ind_shell = []
1325-
for d, i in zip(dist, ind):
1324+
for d, i in zip(dist, ind, strict=True):
13261325
id_list = get_cluster(d[d < radius], i[d < radius])
13271326
ia_shells_dict = {}
13281327
for i_shell_list in id_list:
@@ -1361,7 +1360,7 @@ def get_neighbors(
13611360
structure: Atoms,
13621361
num_neighbors: int = 12,
13631362
tolerance: int = 2,
1364-
id_list: Optional[list] = None,
1363+
id_list: list | None = None,
13651364
cutoff_radius: float = np.inf,
13661365
width_buffer: float = 1.2,
13671366
mode: str = "filled",
@@ -1400,12 +1399,12 @@ def _get_neighbors(
14001399
structure: Atoms,
14011400
num_neighbors: int = 12,
14021401
tolerance: int = 2,
1403-
id_list: Optional[list] = None,
1402+
id_list: list | None = None,
14041403
cutoff_radius: float = np.inf,
14051404
width_buffer: float = 1.2,
14061405
get_tree: bool = False,
14071406
norm_order: int = 2,
1408-
) -> Union[Neighbors, Tree]:
1407+
) -> Neighbors | Tree:
14091408
"""
14101409
Get the neighbors of atoms in a structure.
14111410

structuretoolkit/analyse/pyscal.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) Max-Planck-Institut für Eisenforschung GmbH - Computational Materials Design (CM) Department
22
# Distributed under the terms of "New BSD License", see the LICENSE file.
33

4-
from typing import Any, Optional, Union
4+
from typing import Any
55

66
import numpy as np
77
from ase.atoms import Atoms
@@ -24,10 +24,10 @@ def get_steinhardt_parameters(
2424
structure: Atoms,
2525
neighbor_method: str = "cutoff",
2626
cutoff: float = 0.0,
27-
n_clusters: Optional[int] = 2,
28-
q: Optional[tuple] = None,
27+
n_clusters: int | None = 2,
28+
q: tuple | None = None,
2929
averaged: bool = False,
30-
) -> Union[tuple[np.ndarray], tuple[np.ndarray, np.ndarray]]:
30+
) -> tuple[np.ndarray] | tuple[np.ndarray, np.ndarray]:
3131
"""
3232
Calculate Steinhardts parameters
3333
@@ -55,7 +55,7 @@ def get_steinhardt_parameters(
5555

5656
cl = cluster.KMeans(n_clusters=n_clusters)
5757

58-
ind = cl.fit(list(zip(*sysq))).labels_
58+
ind = cl.fit(list(zip(*sysq, strict=True))).labels_
5959
return sysq, ind
6060
else:
6161
return sysq
@@ -80,7 +80,7 @@ def get_centro_symmetry_descriptors(
8080

8181
def get_diamond_structure_descriptors(
8282
structure: Atoms, mode: str = "total", ovito_compatibility: bool = False
83-
) -> Union[dict[str, int], np.ndarray]:
83+
) -> dict[str, int] | np.ndarray:
8484
"""
8585
Analyse diamond structure
8686
@@ -197,7 +197,10 @@ def get_adaptive_cna_descriptors(
197197
if not ovito_compatibility:
198198
return cna
199199
else:
200-
return {o: cna[p] for o, p in zip(ovito_parameter, pyscal_parameter)}
200+
return {
201+
o: cna[p]
202+
for o, p in zip(ovito_parameter, pyscal_parameter, strict=True)
203+
}
201204
else:
202205
cnalist = np.array(sys.atoms.structure)
203206
if mode == "numeric":
@@ -241,7 +244,7 @@ def find_solids(
241244
q: int = 6,
242245
right: bool = True,
243246
return_sys: bool = False,
244-
) -> Union[int, Any]:
247+
) -> int | Any:
245248
"""
246249
Get the number of solids or the corresponding pyscal system.
247250
Calls necessary pyscal methods as described in https://pyscal.org/en/latest/methods/03_solidliquid.html.

0 commit comments

Comments
 (0)