Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-118761: Improve import time of pprint #122725

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 7, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply suggestions from code review
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
  • Loading branch information
hugovk and AA-Turner authored Aug 7, 2024
commit 07cffca9a441c6f696e2133dd5139ea7b4d5e26e
6 changes: 3 additions & 3 deletions 6 Lib/pprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def _format(self, object, stream, indent, allowance, context, level):
if len(rep) > max_width:
p = self._dispatch.get(type(object).__repr__, None)
# Lazy import to improve module import time
import dataclasses as _dataclasses
from dataclasses import is_dataclass

if p is not None:
context[objid] = 1
Expand All @@ -207,11 +207,11 @@ def _format(self, object, stream, indent, allowance, context, level):

def _pprint_dataclass(self, object, stream, indent, allowance, context, level):
# Lazy import to improve module import time
import dataclasses as _dataclasses
from dataclasses import fields as dataclass_fields

cls_name = object.__class__.__name__
indent += len(cls_name) + 1
items = [(f.name, getattr(object, f.name)) for f in _dataclasses.fields(object) if f.repr]
items = [(f.name, getattr(object, f.name)) for f in dataclass_fields(object) if f.repr]
stream.write(cls_name + '(')
self._format_namespace_items(items, stream, indent, allowance, context, level)
stream.write(')')
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.