File tree Expand file tree Collapse file tree 2 files changed +15
-8
lines changed Expand file tree Collapse file tree 2 files changed +15
-8
lines changed Original file line number Diff line number Diff line change 1010from collections import defaultdict , deque
1111from functools import partial
1212from inspect import getfullargspec
13- from io import StringIO
13+ from io import StringIO , TextIOWrapper
1414from itertools import groupby
1515from pathlib import Path
1616from 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." ,
Original file line number Diff line number Diff 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.",
You can’t perform that action at this time.
0 commit comments