Skip to content

Commit 60464fd

Browse files
authored
Fix all ruff DOC202 (materialsproject#4067)
* fix all ruff DOC202 https://docs.astral.sh/ruff/rules/docstring-extraneous-returns/ * doc str format: "list[...]: List of ..." -> "list[...]: ..."
1 parent 7743ac7 commit 60464fd

File tree

16 files changed

+63
-81
lines changed

16 files changed

+63
-81
lines changed

pyproject.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,6 @@ include = ["pymatgen", "pymatgen.*"]
165165
lint = ["mypy>=1.10.0", "pre-commit>=3.7.1", "ruff>=0.4.9"]
166166
test = ["pytest-cov>=5.0.0", "pytest-split>=0.9.0", "pytest>=8.2.2"]
167167

168-
[tool.versioningit.vcs]
169-
method = "git"
170-
default-tag = "0.0.1"
171-
172168
[tool.cibuildwheel.linux]
173169
archs = ["auto64"]
174170
skip = ["*musllinux*"]

src/pymatgen/alchemy/filters.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,16 +214,21 @@ def get_spg_num(struct: Structure) -> int:
214214
class RemoveExistingFilter(AbstractStructureFilter):
215215
"""This filter removes structures existing in a given list from the transmuter."""
216216

217-
def __init__(self, existing_structures, structure_matcher=None, symprec=None):
217+
def __init__(
218+
self,
219+
existing_structures: list[Structure],
220+
structure_matcher: dict | StructureMatcher | None = None,
221+
symprec: float | None = None,
222+
) -> None:
218223
"""Remove existing structures based on the structure matcher
219224
and symmetry (if symprec is given).
220225
221226
Args:
222-
existing_structures: List of existing structures to compare with
223-
structure_matcher: Provides a structure matcher to be used for
227+
existing_structures (list[Structure]): Existing structures to compare with.
228+
structure_matcher (dict | StructureMatcher, optional): Will be used for
224229
structure comparison.
225-
symprec: The precision in the symmetry finder algorithm if None (
226-
default value), no symmetry check is performed and only the
230+
symprec (float | None): The precision in the symmetry finder algorithm.
231+
If None (default value), no symmetry check is performed and only the
227232
structure matcher is used. A recommended value is 1e-5.
228233
"""
229234
self.symprec = symprec
@@ -241,15 +246,15 @@ def get_sg(s):
241246
finder = SpacegroupAnalyzer(s, symprec=self.symprec)
242247
return finder.get_space_group_number()
243248

244-
for s in self.existing_structures:
249+
for struct in self.existing_structures:
245250
if (
246251
(
247252
self.structure_matcher._comparator.get_hash(structure.composition)
248-
== self.structure_matcher._comparator.get_hash(s.composition)
253+
== self.structure_matcher._comparator.get_hash(struct.composition)
249254
and self.symprec is None
250255
)
251-
or get_sg(s) == get_sg(structure)
252-
) and self.structure_matcher.fit(s, structure):
256+
or get_sg(struct) == get_sg(structure)
257+
) and self.structure_matcher.fit(struct, structure):
253258
return False
254259

255260
self.structure_list.append(structure)

src/pymatgen/alchemy/materials.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def __init__(
4747
4848
Args:
4949
structure (Structure): Input structure
50-
transformations (list[Transformation]): List of transformations to apply.
50+
transformations (list[Transformation]): Transformations to apply.
5151
history (list[Transformation]): Previous history.
5252
other_parameters (dict): Additional parameters to be added.
5353
"""
@@ -355,7 +355,7 @@ def to_snl(self, authors: list[str], **kwargs) -> StructureNL:
355355
"""Generate a StructureNL from TransformedStructure.
356356
357357
Args:
358-
authors (List[str]): List of authors contributing to the generated StructureNL.
358+
authors (List[str]): Authors contributing to the generated StructureNL.
359359
**kwargs (Any): All kwargs supported by StructureNL.
360360
361361
Returns:

src/pymatgen/alchemy/transmuters.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class StandardTransmuter:
3737
transformations on many structures to generate TransformedStructures.
3838
3939
Attributes:
40-
transformed_structures (list[Structure]): List of all transformed structures.
40+
transformed_structures (list[Structure]): All transformed structures.
4141
"""
4242

4343
def __init__(
@@ -262,7 +262,7 @@ def from_filenames(cls, filenames, transformations=None, primitive=True, extend_
262262
containing multiple structures.
263263
264264
Args:
265-
filenames: List of strings of the CIF files
265+
filenames (list[str]): The CIF file paths.
266266
transformations: New transformations to be applied to all
267267
structures
268268
primitive: Same meaning as in __init__.
@@ -286,7 +286,7 @@ class PoscarTransmuter(StandardTransmuter):
286286
def __init__(self, poscar_string, transformations=None, extend_collection=False):
287287
"""
288288
Args:
289-
poscar_string: List of POSCAR strings
289+
poscar_string (list[str]): POSCAR strings.
290290
transformations: New transformations to be applied to all
291291
structures.
292292
extend_collection: Whether to use more than one output structure
@@ -301,7 +301,7 @@ def from_filenames(cls, poscar_filenames, transformations=None, extend_collectio
301301
POSCAR filenames.
302302
303303
Args:
304-
poscar_filenames: List of POSCAR filenames
304+
poscar_filenames (list[str]): The POSCAR file paths.
305305
transformations: New transformations to be applied to all
306306
structures.
307307
extend_collection:

src/pymatgen/analysis/adsorption.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,8 @@ def ensemble_center(cls, site_list, indices, cartesian=True):
348348
sites. Helper method for the find_adsorption_sites algorithm.
349349
350350
Args:
351-
site_list (list of sites): list of sites
352-
indices (list of ints): list of ints from which to select
351+
site_list (list[Site]): sites from which to select
352+
indices (list[int]): indices of sites from which to select
353353
sites from site list
354354
cartesian (bool): whether to get average fractional or
355355
Cartesian coordinate
@@ -543,7 +543,7 @@ def generate_substitution_structures(
543543
atom (str): atom corresponding to substitutional dopant
544544
sub_both_sides (bool): If true, substitute an equivalent
545545
site on the other surface
546-
target_species (list): List of specific species to substitute
546+
target_species (list): Specific species to substitute
547547
range_tol (float): Find viable substitution sites at a specific
548548
distance from the surface +- this tolerance
549549
dist_from_surf (float): Distance from the surface to find viable

src/pymatgen/analysis/bond_valence.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,18 +460,18 @@ def get_z_ordered_elmap(comp):
460460
return sorted((elem, comp[elem]) for elem in comp)
461461

462462

463-
def add_oxidation_state_by_site_fraction(structure, oxidation_states):
463+
def add_oxidation_state_by_site_fraction(structure: Structure, oxidation_states: list[list[int]]) -> Structure:
464464
"""
465465
Add oxidation states to a structure by fractional site.
466466
467467
Args:
468-
oxidation_states (list): List of list of oxidation states for each
468+
oxidation_states (list[list[int]]): List of list of oxidation states for each
469469
site fraction for each site.
470470
e.g. [[2, 4], [3], [-2], [-2], [-2]]
471471
"""
472472
try:
473473
for idx, site in enumerate(structure):
474-
new_sp = defaultdict(float)
474+
new_sp: dict[Species, float] = defaultdict(float)
475475
for j, (el, occu) in enumerate(get_z_ordered_elmap(site.species)):
476476
specie = Species(el.symbol, oxidation_states[idx][j])
477477
new_sp[specie] += occu

src/pymatgen/analysis/chemenv/connectivity/connected_components.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,6 @@ def __init__(
211211
environments_data: Data of environment nodes.
212212
links_data: Data of links between environment nodes.
213213
graph: Graph of the connected component.
214-
215-
Returns:
216-
ConnectedComponent: Instance of this class
217214
"""
218215
self._periodicity_vectors: list[list] | None = None
219216
self._primitive_reduced_connected_subgraph = None

src/pymatgen/analysis/chemenv/coordination_environments/voronoi.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -563,14 +563,14 @@ def maps_and_surfaces(
563563
maps_and_surfaces = []
564564
for cn, value in self._unique_coordinated_neighbors_parameters_indices[isite].items():
565565
for imap, list_parameters_indices in enumerate(value):
566-
thissurf = 0.0
566+
this_surf = 0.0
567567
for idp, iap, iacb in list_parameters_indices:
568568
if iacb in additional_conditions:
569-
thissurf += surfaces[idp, iap]
569+
this_surf += surfaces[idp, iap]
570570
maps_and_surfaces.append(
571571
{
572572
"map": (cn, imap),
573-
"surface": thissurf,
573+
"surface": this_surf,
574574
"parameters_indices": list_parameters_indices,
575575
}
576576
)
@@ -596,14 +596,14 @@ def maps_and_surfaces_bounded(self, isite, surface_calculation_options=None, add
596596
maps_and_surfaces = []
597597
for cn, value in self._unique_coordinated_neighbors_parameters_indices[isite].items():
598598
for imap, list_parameters_indices in enumerate(value):
599-
thissurf = 0.0
599+
this_surf = 0.0
600600
for idp, iap, iacb in list_parameters_indices:
601601
if iacb in additional_conditions:
602-
thissurf += surfaces[idp, iap]
602+
this_surf += surfaces[idp, iap]
603603
maps_and_surfaces.append(
604604
{
605605
"map": (cn, imap),
606-
"surface": thissurf,
606+
"surface": this_surf,
607607
"parameters_indices": list_parameters_indices,
608608
}
609609
)

src/pymatgen/analysis/interfaces/zsl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def __init__(
108108
self.max_angle_tol = max_angle_tol
109109
self.bidirectional = bidirectional
110110

111-
def generate_sl_transformation_sets(self, film_area, substrate_area):
111+
def generate_sl_transformation_sets(self, film_area: int, substrate_area: int) -> Iterator[tuple]:
112112
"""Generate transformation sets for film/substrate pair given the
113113
area of the unit cell area for the film and substrate. The
114114
transformation sets map the film and substrate unit cells to super
@@ -118,7 +118,7 @@ def generate_sl_transformation_sets(self, film_area, substrate_area):
118118
film_area (int): the unit cell area for the film
119119
substrate_area (int): the unit cell area for the substrate
120120
121-
Returns:
121+
Yields:
122122
transformation_sets: a set of transformation_sets defined as:
123123
1.) the transformation matrices for the film to create a
124124
super lattice of area i*film area

src/pymatgen/analysis/piezo_sensitivity.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,25 +178,24 @@ def __init__(self, structure: Structure, ist, pointops, tol: float = 1e-3):
178178
self.structure = structure
179179
self.ist = ist
180180
self.pointops = pointops
181-
self.IST_operations = None
181+
self.IST_operations: list[list[list]] = []
182182

183183
obj = self.ist
184184
if not (obj - np.transpose(obj, (0, 1, 3, 2)) < tol).all():
185185
warnings.warn("Input internal strain tensor does not satisfy standard symmetries")
186186

187-
def get_IST_operations(self, opstol=1e-3):
187+
def get_IST_operations(self, opstol=1e-3) -> list[list[list]]:
188188
"""Get the symmetry operations which maps the tensors
189189
belonging to equivalent sites onto each other in the form
190-
[site index 1, site index 2, [Symmops mapping from site
190+
[site index 1, site index 2, [SymmOps mapping from site
191191
index 1 to site index 2]].
192192
193193
Args:
194194
opstol (float): tolerance for determining if a symmetry
195195
operation relates two sites
196196
197197
Returns:
198-
list of symmetry operations mapping equivalent sites and
199-
the indexes of those sites.
198+
list[list[list]]: symmetry operations mapping equivalent sites and the indexes of those sites.
200199
"""
201200
struct = self.structure
202201
ops = SpacegroupAnalyzer(struct).get_symmetry_operations(cartesian=True)
@@ -207,18 +206,19 @@ def get_IST_operations(self, opstol=1e-3):
207206
if op not in uniq_point_ops:
208207
uniq_point_ops.append(op)
209208

210-
IST_operations = []
211-
for atom in range(len(self.ist)):
209+
IST_operations: list[list[list]] = []
210+
for atom_idx in range(len(self.ist)):
212211
IST_operations.append([])
213-
for j in range(atom):
212+
for j in range(atom_idx):
214213
for op in uniq_point_ops:
215214
new = op.transform_tensor(self.ist[j])
216215

217216
# Check the matrix it references
218-
if np.allclose(new, self.ist[atom], atol=opstol):
219-
IST_operations[atom].append([j, op])
217+
if np.allclose(new, self.ist[atom_idx], atol=opstol):
218+
IST_operations[atom_idx].append([j, op])
220219

221220
self.IST_operations = IST_operations
221+
return IST_operations
222222

223223
def get_rand_IST(self, max_force=1):
224224
"""Generate a random internal strain tensor which obeys a structure's

0 commit comments

Comments
 (0)