Skip to content

Commit

Permalink
Merge pull request #818 from eth-brownie/fix-0x-black
Browse files Browse the repository at this point in the history
Replace `0x` with empty bytes prior to parsing with black
  • Loading branch information
iamdefinitelyahuman authored Oct 22, 2020
2 parents 564ab8a + 733e2e1 commit c5595db
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion brownie/network/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -1016,10 +1016,25 @@ def _step_internal(
return key


def _convert_0x_to_empty_bytes(value: Any) -> Any:
# black cannot parse `0x` without any trailing zeros, so we temporarily
# replace it with an empty bytestring
final = []
for item in value:
if isinstance(item, (list, tuple)):
final.append(_convert_0x_to_empty_bytes(item))
elif item == "0x":
final.append(b"")
else:
final.append(item)
return type(value)(final)


def _format(value: Any) -> str:
if isinstance(value, (list, tuple)):
value = _convert_0x_to_empty_bytes(value)
mode = black.FileMode(line_length=60)
black.format_str(str(value), mode=mode)
value = black.format_str(str(value), mode=mode).replace('b""', "0x")
return str(value)


Expand Down

0 comments on commit c5595db

Please sign in to comment.