Skip to content

Commit 96aa286

Browse files
committed
Some more typing fixes.
1 parent c078749 commit 96aa286

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ exclude_also = [
301301
ignore_missing_imports = true
302302
namespace_packages = true
303303
no_implicit_optional = false
304-
disable_error_code = ["annotation-unchecked", "override", "operator", "attr-defined"] #, "union-attr", "operator", "arg-type", "index", "call-arg", "return-value", "assignment", "attr-defined"]
304+
disable_error_code = ["annotation-unchecked", "override", "operator", "attr-defined", "union-attr", "arg-type"] #, "operator", "arg-type", "index", "call-arg", "return-value", "assignment", "attr-defined"]
305305
exclude = ['src/pymatgen/analysis', 'src/pymatgen/io', 'src/pymatgen/cli', 'src/pymatgen/electronic_structure', 'src/pymatgen/phonon']
306306
plugins = ["numpy.typing.mypy_plugin"]
307307

src/pymatgen/core/structure.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2555,7 +2555,7 @@ def get_primitive_structure(
25552555
tolerance: float = 0.25,
25562556
use_site_props: bool = False,
25572557
constrain_latt: list | dict | None = None,
2558-
) -> Self:
2558+
) -> Self | Structure:
25592559
"""Find a smaller unit cell than the input. Sometimes it doesn't
25602560
find the smallest possible one, so this method is recursively called
25612561
until it is unable to find a smaller cell.
@@ -3190,7 +3190,7 @@ def from_file( # type:ignore[override]
31903190

31913191
fname = os.path.basename(filename)
31923192
with zopen(filename, mode="rt", errors="replace", encoding="utf-8") as file:
3193-
contents = file.read()
3193+
contents: str = file.read()
31943194
if fnmatch(fname.lower(), "*.cif*") or fnmatch(fname.lower(), "*.mcif*"):
31953195
return cls.from_str(
31963196
contents,
@@ -4013,7 +4013,7 @@ def to(self, filename: str = "", fmt: str = "") -> str | None:
40134013
json_str = json.dumps(self.as_dict())
40144014
if filename:
40154015
with zopen(filename, mode="wt", encoding="utf-8") as file:
4016-
file.write(json_str)
4016+
file.write(json_str.encode("utf-8"))
40174017
return json_str
40184018
elif fmt in {"yaml", "yml"} or fnmatch(filename, "*.yaml*") or fnmatch(filename, "*.yml*"):
40194019
yaml = YAML()
@@ -4022,7 +4022,7 @@ def to(self, filename: str = "", fmt: str = "") -> str | None:
40224022
yaml_str = str_io.getvalue()
40234023
if filename:
40244024
with zopen(filename, mode="wt", encoding="utf-8") as file:
4025-
file.write(yaml_str)
4025+
file.write(yaml_str.encode("utf-8"))
40264026
return yaml_str
40274027
else:
40284028
from pymatgen.io.babel import BabelMolAdaptor
@@ -4088,7 +4088,7 @@ def from_str( # type:ignore[override]
40884088
return cls.from_sites(mol, properties=mol.properties)
40894089

40904090
@classmethod
4091-
def from_file(cls, filename: PathLike) -> Self | None: # type:ignore[override]
4091+
def from_file(cls, filename: PathLike) -> IMolecule | Molecule: # type:ignore[override]
40924092
"""Read a molecule from a file. Supported formats include xyz,
40934093
gaussian input (gjf|g03|g09|com|inp), Gaussian output (.out|and
40944094
pymatgen's JSON-serialized molecules. Using openbabel,
@@ -4104,7 +4104,7 @@ def from_file(cls, filename: PathLike) -> Self | None: # type:ignore[override]
41044104
filename = str(filename)
41054105

41064106
with zopen(filename, mode="rt", encoding="utf-8") as file:
4107-
contents = file.read()
4107+
contents: str = file.read().decode("utf-8")
41084108
fname = filename.lower()
41094109
if fnmatch(fname, "*.xyz*"):
41104110
return cls.from_str(contents, fmt="xyz")

0 commit comments

Comments
 (0)