Skip to content

Commit 6ca7022

Browse files
committed
Revert "revert support of TextIOWrapper"
This reverts commit ae5c0f1.
1 parent ae5c0f1 commit 6ca7022

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/pymatgen/io/cif.py

Lines changed: 1 addition & 8 deletions
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, TextIOWrapper
13+
from io import StringIO
1414
from itertools import groupby
1515
from pathlib import Path
1616
from typing import TYPE_CHECKING, Literal, cast
@@ -344,13 +344,6 @@ 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()
354347
elif isinstance(filename, StringIO):
355348
warnings.warn(
356349
"Initializing CifParser from StringIO is deprecated, use `from_str()` instead.",

tests/io/test_cif.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,16 @@ 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+
180+
for struct in parser.parse_structures():
181+
assert struct.formula == "V4 O6"
182+
173183
# Test init from TextIOWrapper
174184
with (
175185
pytest.warns(DeprecationWarning, match="Initializing CifParser from TextIOWrapper"),

0 commit comments

Comments
 (0)