|
38 | 38 | import sys as _sys |
39 | 39 | import types as _types |
40 | 40 | from io import StringIO as _StringIO |
41 | | - |
42 | 41 | lazy import _colorize |
| 42 | +lazy import re |
43 | 43 | 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 |
44 | 46 |
|
45 | 47 | __all__ = ["pprint","pformat","isreadable","isrecursive","saferepr", |
46 | 48 | "PrettyPrinter", "pp"] |
@@ -263,9 +265,6 @@ def _format(self, object, stream, indent, allowance, context, level): |
263 | 265 | max_width = self._width - indent - allowance |
264 | 266 | if len(rep) > max_width: |
265 | 267 | p = self._dispatch.get(type(object).__repr__, None) |
266 | | - # Lazy import to improve module import time |
267 | | - from dataclasses import is_dataclass |
268 | | - |
269 | 268 | if p is not None: |
270 | 269 | context[objid] = 1 |
271 | 270 | p(self, object, stream, indent, allowance, context, level + 1) |
@@ -306,9 +305,6 @@ def _write_indent_padding(self, write): |
306 | 305 | write((self._indent_per_level - 1) * " ") |
307 | 306 |
|
308 | 307 | 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 | | - |
312 | 308 | cls_name = object.__class__.__name__ |
313 | 309 | if self._expand: |
314 | 310 | indent += self._indent_per_level |
@@ -488,9 +484,6 @@ def _pprint_str(self, object, stream, indent, allowance, context, level): |
488 | 484 | if len(rep) <= max_width1: |
489 | 485 | chunks.append(rep) |
490 | 486 | else: |
491 | | - # Lazy import to improve module import time |
492 | | - import re |
493 | | - |
494 | 487 | # A list of alternating (non-space, space) strings |
495 | 488 | parts = re.findall(r'\S*\s*', line) |
496 | 489 | assert parts |
|
0 commit comments