Skip to content

Record and emit all special case lines from docstrings during parsing#8

Closed
Copilot wants to merge 4 commits into
masterfrom
copilot/record-special-case-lines
Closed

Record and emit all special case lines from docstrings during parsing#8
Copilot wants to merge 4 commits into
masterfrom
copilot/record-special-case-lines

Conversation

Copy link
Copy Markdown

Copilot AI commented Jan 16, 2026

Special cases parsed from docstrings need to be tracked and emitted for debugging/verification purposes. This includes all lines matching the special case pattern, regardless of whether they successfully parse or trigger warnings.

Changes

  • Global registry: Added special_cases_registry list to store records in format "function_name: case_line"

  • Recording in parsers: Modified parse_unary_case_block and parse_binary_case_block to record every case line matching r_case pattern during iteration, including:

    • Successfully parsed cases
    • Cases failing with ParseError
    • Cases triggering warnings
  • Emission mechanism: Added test_print_special_cases_registry() to print complete registry during test runs

Example Output

SPECIAL CASES REGISTRY
================================================================================
abs: If ``x_i`` is ``NaN``, the result is ``NaN``
sinh: If ``x_i`` is ``NaN``, the result is ``NaN``
sinh: If ``x_i`` is ``+0``, the result is ``+0``
sinh: If ``x_i`` is ``-0``, the result is ``-0``
...
================================================================================
Total special cases recorded: 473
================================================================================

Lines not matching r_case pattern (e.g., "For floating-point operands") are correctly excluded.

Original prompt

Summary

When parsing special cases from docstrings, record the exact line for each special case along with the function name. Emit this list during the test run.

Requirements

  1. Record special case lines: When parsing special cases in parse_unary_case_block and parse_binary_case_block, record each special case line with its function name in the format: "function_name: special_case_line".

  2. Include all lines: Record ALL special case lines that match the r_case pattern, including:

    • Successfully parsed cases
    • Cases that failed to parse (with ParseError)
    • Cases that triggered warnings
  3. Exclude non-case lines: Do NOT include lines like "For real-valued floating-point operands," that don't match the r_case pattern (i.e., lines that don't start with - ).

  4. Store globally: Create a global list (e.g., special_cases_registry) to store these records.

  5. Emit during tests: Output the complete list of recorded special cases at an appropriate point during test execution. This could be:

    • As a fixture that prints the list before tests run
    • As a separate test function that prints the registry
    • Or another appropriate mechanism

Example Output Format

For the abs function with the special case "If x_i is NaN, the result is NaN", the record should be:

abs: If x_i is NaN, the result is NaN

For the sinh function with multiple cases:

sinh: If x_i is NaN, the result is NaN
sinh: If x_i is +0, the result is +0
sinh: If x_i is -0, the result is -0
sinh: If x_i is +infinity, the result is +infinity
sinh: If x_i is -infinity, the result is -infinity

Implementation Notes

  • Modify parse_unary_case_block to record each case line in the format "{func_name}: {case_str}"
  • Modify parse_binary_case_block similarly
  • The recording should happen for every iteration of r_case.finditer(case_block), regardless of whether parsing succeeds or fails
  • Consider adding a conftest.py fixture or a dedicated test function to print the registry

Files to Modify

  • array_api_tests/test_special_cases.py - Add recording logic and emission mechanism

This pull request was created from Copilot chat.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits January 16, 2026 16:49
Co-authored-by: ev-br <2133832+ev-br@users.noreply.github.com>
Co-authored-by: ev-br <2133832+ev-br@users.noreply.github.com>
Co-authored-by: ev-br <2133832+ev-br@users.noreply.github.com>
Copilot AI changed the title [WIP] Record special case lines during docstring parsing Record and emit all special case lines from docstrings during parsing Jan 16, 2026
Copilot AI requested a review from ev-br January 16, 2026 16:56
@ev-br ev-br closed this Jan 16, 2026
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.

2 participants