Whole file

karlicoss/orgparse

The author described this change as fix regression in orgparse.load method for file-like objects. It counts as a record because the check below fails on the code as it stood at ce8f6ccf6 and passes on 45b366eb5, with nothing else changed between the two runs.

Fix saved2021-01-08
Sharing licenceBSD-2-Clause · LICENSE
Change size+11 9

What the code was meant to do, written into the code itself as a save note

fix regression in orgparse.load method for file-like objects

The change

107107 # [[[end]]]
108108
109109 import codecs
110-from typing import Iterable
110+from pathlib import Path
111+from typing import Iterable, Union, Optional, TextIO
111112
112-from .node import parse_lines, OrgNode # todo basenode??
113+
114+from .node import parse_lines, OrgEnv, OrgNode # todo basenode??
113115 from .utils.py3compat import basestring
114116
115117 __author__ = 'Takafumi Arakaki, Dmitrii Gerasimov'
117119 __all__ = ["load", "loads", "loadi"]
118120
119121
120-def load(path, env=None):
122+def load(path: Union[str, Path, TextIO], env: Optional[OrgEnv]=None) -> OrgNode:
121123 """
122124 Load org-mode document from a file.
123125
127129 :rtype: :class:`orgparse.node.OrgRootNode`
128130
129131 """
130- path = str(path) # in case of pathlib.Path
131- if isinstance(path, basestring):
132- orgfile = codecs.open(path, encoding='utf8')
133- filename = path
132+ orgfile: TextIO
133+ if isinstance(path, (str, Path)):
134+ orgfile = codecs.open(str(path), encoding='utf8')
135+ filename = str(path)
134136 else:
135137 orgfile = path
136138 filename = path.name if hasattr(path, 'name') else '<file-like>'
138140 filename=filename, env=env)
139141
140142
141-def loads(string: str, filename='<string>', env=None) -> OrgNode:
143+def loads(string: str, filename: str='<string>', env: Optional[OrgEnv]=None) -> OrgNode:
142144 """
143145 Load org-mode document from a string.
144146
148150 return loadi(string.splitlines(), filename=filename, env=env)
149151
150152
151-def loadi(lines: Iterable[str], filename='<lines>', env=None) -> OrgNode:
153+def loadi(lines: Iterable[str], filename: str='<lines>', env: Optional[OrgEnv]=None) -> OrgNode:
152154 """
153155 Load org-mode document from an iterative object.
154156

The check that tells the two apart

failpass·orgparse/tests/test_misc.py::test_load_filelike

Check file orgparse/tests/test_misc.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before itce8f6ccf60d6dca60c5f03890d730676a5d1ac21
Broken version dated2020-12-06
Moduleorgparse.__init__
Units changedload, loadi, loads
Fingerprintf2842bf7cfd15c22
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in karlicoss/orgparse