Skip to content

Raise BoxError from box_from_string for YAML when no YAML library is installed - #363

Open
TohruSu wants to merge 1 commit into
cdgriffith:developfrom
TohruSu:fix-box-from-string-yaml-unavailable
Open

TohruSu wants to merge 1 commit into
cdgriffith:developfrom
TohruSu:fix-box-from-string-yaml-unavailable

Conversation

@TohruSu

@TohruSu TohruSu commented Nov 14, 2026

Copy link
Copy Markdown

Without ruamel.yaml or PyYAML installed, box_from_string(content, string_type="yaml") raises TypeError: catching classes that do not inherit from BaseException is not allowed in the pure Python build. When neither library can be imported, from_file.py sets YAMLError = False, and the yaml branch wraps Box.from_yaml(), which then raises BoxError, in except YAMLError:. Python fails while matching that clause. The Cython compiled wheels don't show this, because there the clause simply doesn't match and the BoxList.from_yaml() fallback raises the BoxError, so it only happens with the pure Python wheel or sdist, for example on PyPy or on platforms without a compiled wheel.

This adds the availability check that the toon branch already has, with the message Box.from_yaml() uses, so both builds now raise the same BoxError. The new test puts the module into the no-YAML state the same way test_toon_unavailable does, and fails with the TypeError without the change.

I reproduced the error and checked the fix in a venv without any YAML library, and ran the full test suite, ruff and mypy locally on Windows with Python 3.14.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant