Skip to content

MAINT: Use full class names for pypdf.constants imports - #4402

Open
zeyadrabie wants to merge 1 commit into
py-pdf:mainfrom
zeyadrabie:import-constants-full-names
Open

zeyadrabie wants to merge 1 commit into
py-pdf:mainfrom
zeyadrabie:import-constants-full-names

Conversation

@zeyadrabie

@zeyadrabie zeyadrabie commented Nov 11, 2026 •

Copy link
Copy Markdown

This covers item 1 of #3653: using full class names instead of short aliases when importing from pypdf.constants.

What changed

The code imported its constants under short names like PG and FT, so when you ran into something like PG.CONTENTS you had to scroll up to the imports to see what PG was. I replaced those aliases with the full class names, so it now reads PageAttributes.CONTENTS.

  • 25 aliased imports now use the full class name: 21 imports in 8 library files and 4 in 3 test files
  • 329 uses were renamed to match
  • N814 and N817 are removed from the ruff ignore list, so ruff will flag any new aliased imports of constants
  • 16 lines got longer than 120 characters after the rename, so I wrapped them. Nothing else about them changed.

What I left alone

Aliases that aren't constants, like ChainMap as ChainMapType, are still there. They're outside item 1, so I kept this PR to just the constants.

Checks

ruff, mypy, all the pre-commit hooks and the full test suite pass locally. The test run included the downloaded sample files, so it covers the same tests as CI.

AI disclosure

I used Claude Code with Claude Opus 5.5. It did the rename with a script, wrapped the long lines and ran the checks. I reviewed the full diff before opening this PR.

@codecov

codecov Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.56098% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.87%. Comparing base (77c9a41) to head (4036b4d).

Files with missing lines Patch % Lines
pypdf/generic/_data_structures.py 75.00% 2 Missing and 1 partial ⚠️
pypdf/_doc_common.py 96.15% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4402      +/-   ##
==========================================
- Coverage   98.87%   98.87%   -0.01%     
==========================================
  Files          59       59              
  Lines       12297    12277      -20     
  Branches     2342     2342              
==========================================
- Hits        12159    12139      -20     
  Misses         68       68              
  Partials       70       70              

☔ View full report in Codecov by Harness.
📢 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.

@stefan6419846 stefan6419846 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please review the merge conflicts.

@zeyadrabie
zeyadrabie force-pushed the import-constants-full-names branch from fa55dda to 4036b4d Compare November 13, 2026 00:15

This branch has not been deployed

No deployments
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