Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
ml-evs committed Dec 4, 2023
1 parent 907bafb commit 9a1ccc0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions optimade/models/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,12 @@ def _reduce_or_anonymize_formula(
"""Takes an input formula, reduces it and either alphabetizes or anonymizes it."""
import sys

numbers = [int(n.strip() or 1) for n in re.split(r"[A-Z][a-z]*", formula)[1:]]
numbers: list[int] = [
int(n.strip() or 1) for n in re.split(r"[A-Z][a-z]*", formula)[1:]
]
# Need to remove leading 1 from split and convert to ints

species = re.findall("[A-Z][a-z]*", formula)
species: list[str] = re.findall("[A-Z][a-z]*", formula)

if sys.version_info[1] >= 9:
gcd = math.gcd(*numbers)
Expand All @@ -198,7 +200,7 @@ def _reduce_or_anonymize_formula(
species = [s for _, s in zip(numbers, anonymous_element_generator())]

elif alphabetize:
species, numbers = zip(*sorted(zip(species, numbers)))
species, numbers = zip(*sorted(zip(species, numbers))) # type: ignore[assignment]

return "".join(f"{s}{n if n != 1 else ''}" for n, s in zip(numbers, species))

Expand Down
2 changes: 1 addition & 1 deletion requirements-docs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ mike==2.0.0
mkdocs==1.5.3
mkdocs-awesome-pages-plugin==2.9.2
mkdocs-material==9.4.14
mkdocstrings[python]==0.24.0
mkdocstrings[python]==0.24.0

0 comments on commit 9a1ccc0

Please sign in to comment.