Skip to content

Commit 5d5811d

Browse files
committed
Fix support for pprint36 in pretty_print.py
1 parent b063837 commit 5d5811d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

domdf_python_tools/pretty_print.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,15 @@
4444
from pprint36 import PrettyPrinter
4545
from pprint36._pprint import _safe_key # type: ignore
4646

47+
supports_sort_dicts = True
48+
4749
except ImportError:
4850

4951
# stdlib
5052
from pprint import PrettyPrinter, _safe_key # type: ignore
5153

54+
supports_sort_dicts = sys.version_info >= (3, 8)
55+
5256
__all__ = ["FancyPrinter", "simple_repr"]
5357

5458

@@ -63,7 +67,8 @@ class FancyPrinter(PrettyPrinter):
6367
output stream available at construction will be used.
6468
:param compact: If :py:obj:`True`, several items will be combined in one line.
6569
:param sort_dicts: If :py:obj:`True`, dict keys are sorted.
66-
Only takes effect on Python 3.8 and later, or if ``pprint36`` is installed.
70+
Only takes effect on Python 3.8 and later,
71+
or if `pprint36 <https://pypi.org/project/pprint36/>`_ is installed.
6772
"""
6873

6974
def __init__(
@@ -76,13 +81,14 @@ def __init__(
7681
compact: bool = False,
7782
sort_dicts: bool = True,
7883
):
79-
if sys.version_info < (3, 8):
84+
if supports_sort_dicts:
8085
super().__init__(
8186
indent=indent,
8287
width=width,
8388
depth=depth,
8489
stream=stream,
8590
compact=compact,
91+
sort_dicts=sort_dicts,
8692
)
8793
else:
8894
super().__init__(
@@ -91,7 +97,6 @@ def __init__(
9197
depth=depth,
9298
stream=stream,
9399
compact=compact,
94-
sort_dicts=sort_dicts,
95100
)
96101

97102
_dispatch: MutableMapping[Callable, Callable]

0 commit comments

Comments
 (0)