Skip to content

[Code scan] Fix docgen raw-anchor test to toggle the real RAW_ANCHOR global #124

Description

@njzjz

This issue was found by a Codex global code scan of the repository.

Affected code:

dargs/tests/test_docgen.py

Lines 250 to 263 in b4db564

def test_dpmd(self) -> None:
from .dpmdargs import gen_doc
dargs.RAW_ANCHOR = False
docstr = gen_doc(make_anchor=True, make_link=True)
# print("\n\n"+docstr)
# with open("out.rst", "w") as of:
# print(docstr, file=of)
# now testing raw anchor
dargs.RAW_ANCHOR = True
docstr = gen_doc(make_anchor=True, make_link=True)
# print("\n\n"+docstr)
# with open("outr.rst", "w") as of:
# print(docstr, file=of)

dargs/dargs/dargs.py

Lines 38 to 39 in b4db564

INDENT = " " # doc is indented by four spaces
RAW_ANCHOR = False # whether to use raw html anchors or RST ones

from .dargs import Argument, ArgumentEncoder, Variant
__all__ = ["Argument", "ArgumentEncoder", "Variant"]

Problem:
tests/test_docgen.py sets dargs.RAW_ANCHOR = True, but RAW_ANCHOR is defined in dargs.dargs, not exported from dargs.__init__. Assigning to the package creates a new package attribute and leaves the actual global used by make_rst_refid() unchanged.

Reproducer:

import dargs
import dargs.dargs as dd

print(hasattr(dargs, "RAW_ANCHOR"), dd.RAW_ANCHOR)
dargs.RAW_ANCHOR = True
print(dargs.RAW_ANCHOR, dd.RAW_ANCHOR)

Observed behavior:
The package attribute becomes True, but dargs.dargs.RAW_ANCHOR remains False, so the raw-anchor branch is not covered.

Expected behavior:
The test should mutate dargs.dargs.RAW_ANCHOR directly or the package should intentionally export and synchronize that setting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions