Skip to content

refactor: extract private helpers to _docx_utils.py#404

Merged
hf-kklein merged 2 commits intomainfrom
initcleanup
Dec 14, 2025
Merged

refactor: extract private helpers to _docx_utils.py#404
hf-kklein merged 2 commits intomainfrom
initcleanup

Conversation

@hf-kklein
Copy link
Copy Markdown
Contributor

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

Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com

Konstantin and others added 2 commits December 14, 2025 17:52
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>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.py module with 6 helper functions and 4 constants
  • Updated __init__.py to import and use functions from the new module
  • Renamed constants to follow PEP 8 UPPER_CASE convention (e.g., _ebd_key_patternEBD_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
Copy link

Copilot AI Dec 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in comment: "pyton-docx" should be "python-docx".

Suggested change
# 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

Copilot uses AI. Check for mistakes.
```
src/ebdamame/
├── __init__.py # ~120 lines (was ~330)
├── _docx_utils.py # ~120 lines (NEW)
Copy link

Copilot AI Dec 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
├── _docx_utils.py # ~120 lines (NEW)
├── _docx_utils.py # ~152 lines (NEW)

Copilot uses AI. Check for mistakes.
@hf-kklein hf-kklein merged commit 905c74a into main Dec 14, 2025
23 checks passed
@hf-kklein hf-kklein deleted the initcleanup branch December 14, 2025 17:47
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