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.
Projectkarlicoss/orgparse
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
| 107 | 107 | # [[[end]]] | |
| 108 | 108 | ||
| 109 | 109 | import codecs | |
| 110 | - | from typing import Iterable | |
| 110 | + | from pathlib import Path | |
| 111 | + | from typing import Iterable, Union, Optional, TextIO | |
| 111 | 112 | ||
| 112 | - | from .node import parse_lines, OrgNode # todo basenode?? | |
| 113 | + | ||
| 114 | + | from .node import parse_lines, OrgEnv, OrgNode # todo basenode?? | |
| 113 | 115 | from .utils.py3compat import basestring | |
| 114 | 116 | ||
| 115 | 117 | __author__ = 'Takafumi Arakaki, Dmitrii Gerasimov' | |
| ⋯ | |||
| 117 | 119 | __all__ = ["load", "loads", "loadi"] | |
| 118 | 120 | ||
| 119 | 121 | ||
| 120 | - | def load(path, env=None): | |
| 122 | + | def load(path: Union[str, Path, TextIO], env: Optional[OrgEnv]=None) -> OrgNode: | |
| 121 | 123 | """ | |
| 122 | 124 | Load org-mode document from a file. | |
| 123 | 125 | ||
| ⋯ | |||
| 127 | 129 | :rtype: :class:`orgparse.node.OrgRootNode` | |
| 128 | 130 | ||
| 129 | 131 | """ | |
| 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) | |
| 134 | 136 | else: | |
| 135 | 137 | orgfile = path | |
| 136 | 138 | filename = path.name if hasattr(path, 'name') else '<file-like>' | |
| ⋯ | |||
| 138 | 140 | filename=filename, env=env) | |
| 139 | 141 | ||
| 140 | 142 | ||
| 141 | - | def loads(string: str, filename='<string>', env=None) -> OrgNode: | |
| 143 | + | def loads(string: str, filename: str='<string>', env: Optional[OrgEnv]=None) -> OrgNode: | |
| 142 | 144 | """ | |
| 143 | 145 | Load org-mode document from a string. | |
| 144 | 146 | ||
| ⋯ | |||
| 148 | 150 | return loadi(string.splitlines(), filename=filename, env=env) | |
| 149 | 151 | ||
| 150 | 152 | ||
| 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: | |
| 152 | 154 | """ | |
| 153 | 155 | Load org-mode document from an iterative object. | |
| 154 | 156 | ||
The check that tells the two apart
fail→pass·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
- 2020-11-01fix for parsing empty heading