Skip to content

Commit 0b70f4a

Browse files
committed
revert support of TextIOWrapper
1 parent 1af9dd6 commit 0b70f4a

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/pymatgen/io/cif.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from collections import defaultdict, deque
1111
from functools import partial
1212
from inspect import getfullargspec
13-
from io import StringIO
13+
from io import StringIO, TextIOWrapper
1414
from itertools import groupby
1515
from pathlib import Path
1616
from typing import TYPE_CHECKING, Literal, cast
@@ -344,6 +344,13 @@ def __init__(
344344
if isinstance(filename, (str | Path)):
345345
with zopen(filename, mode="rt", encoding="utf-8", errors="replace") as f:
346346
cif_string: str = cast("str", f.read())
347+
elif isinstance(filename, TextIOWrapper):
348+
warnings.warn(
349+
"Initializing CifParser from TextIOWrapper is deprecated, use str or Path instead.",
350+
DeprecationWarning,
351+
stacklevel=2,
352+
)
353+
cif_string = filename.read()
347354
elif isinstance(filename, StringIO):
348355
warnings.warn(
349356
"Initializing CifParser from StringIO is deprecated, use `from_str()` instead.",

tests/io/test_cif.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,15 @@ def test_cif_parser(self):
170170
for struct in parser.parse_structures():
171171
assert struct.formula == "V4 O6"
172172

173-
# Test init from StringIO
174-
with open(f"{TEST_FILES_DIR}/cif/V2O3.cif", encoding="utf-8") as f:
175-
cif_text = f.read()
176-
177-
with pytest.warns(DeprecationWarning, match="Initializing CifParser from StringIO"):
178-
parser = CifParser(StringIO(cif_text))
179-
173+
# Test init from TextIOWrapper
174+
with (
175+
pytest.warns(DeprecationWarning, match="Initializing CifParser from TextIOWrapper"),
176+
open(f"{TEST_FILES_DIR}/cif/V2O3.cif") as file,
177+
):
178+
parser = CifParser(file)
180179
for struct in parser.parse_structures():
181180
assert struct.formula == "V4 O6"
181+
182182
bibtex_str = """
183183
@article{cifref0,
184184
author = "Andersson, G.",

0 commit comments

Comments
 (0)