Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 17, 2025

Moves the _skip and _parse_number functions from _parser.py to a new C extension module _skip_ext.c to make room for future parser enhancements.

Changes

  • Build system: Switched from uv_build to setuptools to support C extensions

    • Added setup.py defining the extension module
    • Updated pyproject.toml with setuptools configuration
  • C extension (_skip_ext.c): 400+ line implementation handling:

    • _skip function: Whitespace and comment skipping
      • Whitespace skipping (space, tab, newline, etc.)
      • Single-line comments (//) with backslash line continuation
      • Multi-line comments (/* */) with proper error on unclosed blocks
      • newline_ok parameter to control newline handling
    • _parse_number function: Number parsing
      • Integer parsing
      • Float parsing (including scientific notation, infinity, NaN)
      • Type-specific parsing (int, float, or int|float)
      • Proper error handling with ParseError
    • Direct buffer usage (no copies) for memory efficiency
    • Proper reference counting and module cleanup
    • Lookup tables for efficient character classification
  • Parser module: Replaced Python implementations with imports from C extension

    • _skip: Direct import from C extension (44 lines removed)
    • _parse_number: Wrapper that calls C version and converts exceptions (32 lines removed)
    • Removed unused lookup tables (_IS_POSSIBLE_FLOAT, _IS_POSSIBLE_INTEGER)

Both C functions maintain identical behavior to the Python versions. All 68 parsing tests pass.

# Before: Python implementations in _parser.py
def _skip(contents: bytes | bytearray, pos: int, *, newline_ok: bool = True) -> int:
    # 44 lines of Python logic
    ...

def _parse_number(contents: bytes | bytearray, pos: int, *, target: type[int] | type[float] | type[int | float] = int | float) -> tuple[int | float, int]:
    # 32 lines of Python logic
    ...

# After: Imports from C extension
from ._skip_ext import _skip
from ._skip_ext import _parse_number as _parse_number_c

def _parse_number(...):
    # Wrapper that converts C ParseError to Python ParseError
    ...
Original prompt

Move the _skip function from the parser module to a new C extension module, to make room for


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

Copilot AI changed the title [WIP] Move _skip function to new C extension module Move _skip function to C extension module Dec 17, 2025
Copilot AI requested a review from gerlero December 17, 2025 05:18
@codecov-commenter
Copy link

codecov-commenter commented Dec 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.59%. Comparing base (5fbadb9) to head (67a7661).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #740      +/-   ##
==========================================
- Coverage   84.67%   84.59%   -0.08%     
==========================================
  Files          27       27              
  Lines        3315     3259      -56     
==========================================
- Hits         2807     2757      -50     
+ Misses        508      502       -6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gerlero
Copy link
Owner

gerlero commented Dec 17, 2025

@copilot also translate the _parse_number function to C

Copy link
Contributor Author

Copilot AI commented Dec 17, 2025

@copilot also translate the _parse_number function to C

Done! Added _parse_number to the C extension in commit 67a7661.

The implementation includes:

  • Support for int, float, and int|float target types
  • Scientific notation and special float values
  • Proper error handling with ParseError
  • All 68 parsing tests pass

The Python wrapper converts the C ParseError to Python ParseError for compatibility with existing code.

Copilot AI changed the title Move _skip function to C extension module Move _skip and _parse_number functions to C extension module Dec 17, 2025
@gerlero gerlero closed this Dec 17, 2025
@gerlero gerlero deleted the copilot/move-skip-function-to-c-extension branch December 17, 2025 08:28
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.

3 participants