Skip to content

Commit dbc68be

Browse files
DanielYang59janosh
andauthored
Fix mypy errors on master branch (materialsproject#3977)
* improve type and simplify iterative_symmetrize * fix type error and tweak types for compatibility * fix packmol type * fix type for site_transformation * ignore type override * fix type for species * docstring tweak * since it says preprocess in comment above, prob not meant to return here --------- Co-authored-by: Janosh Riebesell <[email protected]>
1 parent 0e90789 commit dbc68be

File tree

8 files changed

+181
-140
lines changed

8 files changed

+181
-140
lines changed

src/pymatgen/analysis/structure_prediction/substitution_probability.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def __init__(self, lambda_table=None, alpha=-5):
7676

7777
# create Z and px
7878
self.Z = 0
79-
self._px: dict[Species, float] = defaultdict(float)
79+
self._px: dict[SpeciesLike, float] = defaultdict(float)
8080
for s1, s2 in itertools.product(self.species, repeat=2):
8181
value = math.exp(self.get_lambda(s1, s2))
8282
self._px[s1] += value / 2

src/pymatgen/core/periodic_table.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from enum import Enum, unique
1313
from itertools import combinations, product
1414
from pathlib import Path
15-
from typing import TYPE_CHECKING
15+
from typing import TYPE_CHECKING, overload
1616

1717
import numpy as np
1818
from monty.dev import deprecated
@@ -1597,11 +1597,21 @@ class DummySpecie(DummySpecies):
15971597
"""
15981598

15991599

1600+
@overload
1601+
def get_el_sp(obj: int) -> Element:
1602+
pass
1603+
1604+
1605+
@overload
1606+
def get_el_sp(obj: SpeciesLike) -> Element | Species | DummySpecies:
1607+
pass
1608+
1609+
16001610
@functools.lru_cache
16011611
def get_el_sp(obj: int | SpeciesLike) -> Element | Species | DummySpecies:
1602-
"""Utility method to get an Element, Species or DummySpecies from any input.
1612+
"""Utility function to get an Element, Species or DummySpecies from any input.
16031613
1604-
If obj is in itself an element or a specie, it is returned automatically.
1614+
If obj is an Element or a Species, it is returned as is.
16051615
If obj is an int or a string representing an integer, the Element with the
16061616
atomic number obj is returned.
16071617
If obj is a string, Species parsing will be attempted (e.g. Mn2+). Failing that
@@ -1616,8 +1626,8 @@ def get_el_sp(obj: int | SpeciesLike) -> Element | Species | DummySpecies:
16161626
ValueError: if obj cannot be converted into an Element or Species.
16171627
16181628
Returns:
1619-
Species | Element: with a bias for the maximum number of properties
1620-
that can be determined.
1629+
Element | Species | DummySpecies: with a bias for the maximum number
1630+
of properties that can be determined.
16211631
"""
16221632
# If obj is already an Element or Species, return as is
16231633
if isinstance(obj, (Element, Species, DummySpecies)):

0 commit comments

Comments
 (0)