Skip to content

Commit

Permalink
Convert decimals to integers if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
gartens committed May 16, 2024
1 parent a5909b6 commit 8df2206
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import decimal
import sys

import pytest
Expand Down Expand Up @@ -25,8 +26,13 @@ def add_cur(request, doctest_namespace):
cur.close()

def myprint(*objects, sep=' ', end='\n', file=None, flush=False):
def toint(i):
if isinstance(i, decimal.Decimal) and int(i) == i:
return int(i)
else:
return i
if len(objects) == 1 and isinstance(objects[0], dict):
print('{' + ', '.join(map(lambda i: f'{repr(i[0])}: {repr(i[1])}', sorted(objects[0].items()))) + '}')
print('{' + ', '.join(map(lambda i: f'{repr(i[0])}: {repr(toint(i[1]))}', sorted(objects[0].items()))) + '}')
else:
print(*objects, sep=sep, end=end, file=file, flush=flush)

Expand Down

0 comments on commit 8df2206

Please sign in to comment.