Skip to content

Commit 1d05505

Browse files
committed
Refactor other lazy imports with keyword
1 parent e95aab2 commit 1d05505

1 file changed

Lines changed: 3 additions & 10 deletions

File tree

Lib/pprint.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@
3838
import sys as _sys
3939
import types as _types
4040
from io import StringIO as _StringIO
41-
4241
lazy import _colorize
42+
lazy import re
4343
lazy from _pyrepl.utils import disp_str, gen_colors
44+
lazy from dataclasses import fields as dataclass_fields
45+
lazy from dataclasses import is_dataclass
4446

4547
__all__ = ["pprint","pformat","isreadable","isrecursive","saferepr",
4648
"PrettyPrinter", "pp"]
@@ -263,9 +265,6 @@ def _format(self, object, stream, indent, allowance, context, level):
263265
max_width = self._width - indent - allowance
264266
if len(rep) > max_width:
265267
p = self._dispatch.get(type(object).__repr__, None)
266-
# Lazy import to improve module import time
267-
from dataclasses import is_dataclass
268-
269268
if p is not None:
270269
context[objid] = 1
271270
p(self, object, stream, indent, allowance, context, level + 1)
@@ -306,9 +305,6 @@ def _write_indent_padding(self, write):
306305
write((self._indent_per_level - 1) * " ")
307306

308307
def _pprint_dataclass(self, object, stream, indent, allowance, context, level):
309-
# Lazy import to improve module import time
310-
from dataclasses import fields as dataclass_fields
311-
312308
cls_name = object.__class__.__name__
313309
if self._expand:
314310
indent += self._indent_per_level
@@ -488,9 +484,6 @@ def _pprint_str(self, object, stream, indent, allowance, context, level):
488484
if len(rep) <= max_width1:
489485
chunks.append(rep)
490486
else:
491-
# Lazy import to improve module import time
492-
import re
493-
494487
# A list of alternating (non-space, space) strings
495488
parts = re.findall(r'\S*\s*', line)
496489
assert parts

0 commit comments

Comments
 (0)