Skip to content

Commit

Permalink
Merge pull request #77 from stevepiercy/fix-my-safe-repr
Browse files Browse the repository at this point in the history
Begin fixing functional tests for deform 2.0-branch
  • Loading branch information
stevepiercy authored Aug 19, 2020
2 parents df5d13c + 60c167f commit 8c8222a
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions deformdemo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@


PY3 = sys.version_info[0] == 3
PY38MIN = sys.version_info[0] == 3 and sys.version_info[1] >= 8

if PY3:

Expand Down Expand Up @@ -69,16 +70,12 @@ def __call__(self, method):
# eliminate u''
def my_safe_repr(obj, context, maxlevels, level, sort_dicts=True):

from inspect import signature

if type(obj) == unicode:
obj = obj.encode("utf-8")

# Python 3.8 changed the call signature of pprint._safe_repr.
# In order to support both Python 3.8 and earlier versions
# we have to check its signature before calling
sig = signature(pprint._safe_repr)
if len(sig.parameters) == 5:
# by adding sort_dicts.
if PY38MIN:
return pprint._safe_repr(obj, context, maxlevels, level, sort_dicts)
else:
return pprint._safe_repr(obj, context, maxlevels, level)
Expand Down

0 comments on commit 8c8222a

Please sign in to comment.