Skip to content

Commit

Permalink
Simplify _to_bytes
Browse files Browse the repository at this point in the history
This version is smaller and faster.
  • Loading branch information
liZe committed Jan 5, 2024
1 parent 9ff462e commit 322a602
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions pydyf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ def _to_bytes(item):
"""Convert item to bytes."""
if isinstance(item, bytes):
return item
elif isinstance(item, Object):
return item.data
elif isinstance(item, float):
if item.is_integer():
return f'{int(item):d}'.encode('ascii')
return str(int(item)).encode('ascii')
else:
return f'{item:f}'.rstrip('0').encode('ascii')
elif isinstance(item, int):
return f'{item:d}'.encode('ascii')
elif isinstance(item, Object):
return item.data
return str(item).encode('ascii')


Expand Down

0 comments on commit 322a602

Please sign in to comment.