Skip to content

[FIX] Do not crash on namespaced validators in argument blocks#347

Draft
ehennestad wants to merge 1 commit into
sphinx-contrib:masterfrom
ehennestad:fix-namespaced-validator-crash
Draft

[FIX] Do not crash on namespaced validators in argument blocks#347
ehennestad wants to merge 1 commit into
sphinx-contrib:masterfrom
ehennestad:fix-namespaced-validator-crash

Conversation

@ehennestad

Copy link
Copy Markdown

Summary

A function argument validated by a namespaced function with two or more name parts and no size/class specifier crashes the build:

function out = f(a)
    arguments
        a {x.y.z}
    end
end
File "sphinxcontrib/mat_tree_sitter_parser.py", line 375, in _parse_argument_section
    for arg in arguments:
TypeError: 'NoneType' object is not iterable

The grammar wraps such an argument in an ERROR node, so the argument-block query produces no (property) captures and args is None.

Change

Guard against the None capture in _parse_argument_section and skip the block, mirroring the existing guard in _parse_property_section. The build completes; the unparseable argument simply contributes no metadata (which is not rendered in function output anyway).

Adds a regression test (f_with_namespaced_validator_argument) that crashes without the guard.

Scope

This is a robustness fix — it stops the crash. Correctly parsing these validators requires a fix in the tree-sitter-matlab grammar itself, so this only refs (does not close) the issue.

Refs #335

A function argument validated by a namespaced function with two or more
name parts and no size/class specifier (e.g. {a.b.validator}) is wrapped
in an ERROR node by the grammar, so the argument-block query yields no
parsed arguments and _parse_argument_section raised:

    TypeError: 'NoneType' object is not iterable

Guard against the None capture and skip the block, mirroring the existing
handling in _parse_property_section. The build now completes; the
unparseable argument simply contributes no metadata.

This is a robustness fix. Correctly parsing such validators requires a
fix in the tree-sitter-matlab grammar itself.

Refs sphinx-contrib#335

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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