refactor: extract private helpers to _docx_utils.py#404
Conversation
Move private helper functions and constants from __init__.py to a dedicated internal module _docx_utils.py to reduce bloat. Changes: - Create _docx_utils.py with 6 helper functions and 4 constants - Update __init__.py to import from _docx_utils - Remove is_heading from __all__ (now internal) - Follow PEP8: UPPER_CASE for constants, no underscore prefix on functions since module is already private File sizes: - __init__.py: ~330 lines → ~200 lines - _docx_utils.py: ~120 lines (new) Breaking changes: - is_heading() no longer exported in __all__ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR refactors the codebase by extracting private helper functions and constants from __init__.py into a dedicated internal module _docx_utils.py, reducing code bloat and improving maintainability. The refactoring follows PEP 8 conventions by using UPPER_CASE for constants and removing redundant underscore prefixes from functions in the private module. A minor breaking change removes is_heading() from the public API (__all__), as it's now only used internally.
Key Changes:
- Created new
_docx_utils.pymodule with 6 helper functions and 4 constants - Updated
__init__.pyto import and use functions from the new module - Renamed constants to follow PEP 8 UPPER_CASE convention (e.g.,
_ebd_key_pattern→EBD_KEY_PATTERN)
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/ebdamame/_docx_utils.py |
New internal module containing extracted helper functions (get_tables_and_paragraphs, table_is_an_ebd_table, etc.) and constants (EBD_KEY_PATTERN, DOCX_ARROW_CHAR, etc.) for docx processing |
src/ebdamame/__init__.py |
Updated to import from _docx_utils, replaced direct function definitions and constant declarations with imports, removed is_heading from __all__ exports |
docs/plans/2025-12-14-extract-docx-utils-design.md |
Design documentation describing the refactoring plan, moved functions/constants, and breaking changes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| subsection = 1 | ||
| subsection_title: Optional[str] = None | ||
| for paragraph in paragraphs: | ||
| # since pyton-docx 1.1.2 there are type hints; seems like the style is not guaranteed to be not None |
There was a problem hiding this comment.
Typo in comment: "pyton-docx" should be "python-docx".
| # since pyton-docx 1.1.2 there are type hints; seems like the style is not guaranteed to be not None | |
| # since python-docx 1.1.2 there are type hints; seems like the style is not guaranteed to be not None |
| ``` | ||
| src/ebdamame/ | ||
| ├── __init__.py # ~120 lines (was ~330) | ||
| ├── _docx_utils.py # ~120 lines (NEW) |
There was a problem hiding this comment.
The file size stated here is inaccurate. The actual size of _docx_utils.py is 152 lines (not ~120 lines). Consider updating to match the actual file size.
| ├── _docx_utils.py # ~120 lines (NEW) | |
| ├── _docx_utils.py # ~152 lines (NEW) |
Move private helper functions and constants from init.py to a
dedicated internal module _docx_utils.py to reduce bloat.
Changes:
functions since module is already private
File sizes:
Breaking changes:
🤖 Generated with Claude Code
Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com