Skip to content

Commit 3e3eacf

Browse files
committed
pyright
1 parent 26efef7 commit 3e3eacf

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

python/lib/sift_py/yaml/utils.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
try:
88
import ryml
9-
10-
_HAS_RYML = True
119
except ImportError:
12-
_HAS_RYML = False
10+
ryml = None # type: ignore[assignment]
11+
12+
_HAS_RYML = ryml is not None
1313

1414

1515
def _handle_subdir(path: Path, file_handler: Callable):
@@ -38,7 +38,11 @@ def _rapidyaml_load(path: Path) -> Dict[Any, Any]:
3838
The one semantic diff to watch for is YAML 1.1-isms that rapidyaml (YAML
3939
1.2) does not treat as typed: e.g. ``yes``/``no`` stay strings, and
4040
sexagesimal numbers stay strings. Existing Sift configs do not use these.
41+
42+
Only call this when ``_HAS_RYML`` is true; the ``assert`` below narrows the
43+
type for static analysis and is an invariant the dispatcher upholds.
4144
"""
45+
assert ryml is not None, "rapidyaml is not installed; call _pyyaml_load instead"
4246
with open(path, "rb") as f:
4347
tree = ryml.parse_in_arena(f.read())
4448
resolve = getattr(tree, "resolve", None)

0 commit comments

Comments
 (0)