Skip to content

gh-154675: pprint use lazy imports - #156803

Closed
edvilme wants to merge 3 commits into
python:mainfrom
edvilme:pprint-lazy-import
Closed

gh-154675: pprint use lazy imports#156803
edvilme wants to merge 3 commits into
python:mainfrom
edvilme:pprint-lazy-import

Conversation

@edvilme

@edvilme edvilme commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Use lazy imports instead of inline imports in pprint

CC @johnslavik

Use lazy imports instead of inline imports in pprint
Comment thread Lib/pprint.py Outdated
Comment on lines +42 to +44
lazy from dataclasses import is_dataclass
lazy from dataclasses import fields as dataclass_fields
lazy import re

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Consider _is_dataclass, _dataclass_fields, _re as aliases instead, akin to the imports above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, fixed in e055683

@StanFromIreland

Copy link
Copy Markdown
Member

Do you have any benchmarks for various use cases?

@johnslavik

Copy link
Copy Markdown
Member

Do you have any benchmarks for various use cases?

I think this has zero impact on performance. The imports were always lazy, just inside the functions.

@StanFromIreland StanFromIreland added the type-refactor Code refactoring (with no changes in behavior) label Sep 2, 2026
@StanFromIreland

Copy link
Copy Markdown
Member

Oh right sorry, I don't know how I missed that. I think we can close this, it's just a refactor, and IMO churn. IIRC the PEP had a section that noted this will not be done?

@edvilme
edvilme requested a review from johnslavik September 2, 2026 16:40
@johnslavik

johnslavik commented Sep 2, 2026

Copy link
Copy Markdown
Member

I think so. The linked issue is about improving import times, but this PR does
not improve import time.

@johnslavik

Copy link
Copy Markdown
Member

There are no expensive modules that pprint eagerly imports, so there's not much we can do.

@StanFromIreland StanFromIreland added the pending The issue will be closed if no feedback is provided label Sep 2, 2026
@StanFromIreland

Copy link
Copy Markdown
Member

Yes, I'm sorry but I'm closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review pending The issue will be closed if no feedback is provided type-refactor Code refactoring (with no changes in behavior)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants