Skip to content

Commit

Permalink
Merge pull request #277 from OpShin/feat/allow-bytestring-bytearray
Browse files Browse the repository at this point in the history
Allow ByteString and bytearray synonyms for bytes as type annotations
  • Loading branch information
nielstron authored Oct 27, 2023
2 parents d173216 + 83cc930 commit 3e4b547
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions opshin/tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2039,3 +2039,21 @@ def validator(
# would fail because Address is assigned multiple times and then not constant folded
# TODO find a better way
builder._compile(source_code, constant_folding=True)

def test_bytearray_alternative(self):
source_code = """
def validator(
d: bytearray,
) -> bytes:
return d
"""
eval_uplc(source_code, bytearray(b"hello"))

def test_ByteString_alternative(self):
source_code = """
def validator(
d: ByteString,
) -> bytes:
return d
"""
eval_uplc(source_code, bytearray(b"hello"))
2 changes: 2 additions & 0 deletions opshin/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1774,6 +1774,8 @@ def stringify(self, recursive: bool = False) -> plt.AST:
int.__name__: IntegerType(),
str.__name__: StringType(),
bytes.__name__: ByteStringType(),
"ByteString": ByteStringType(),
bytearray.__name__: ByteStringType(),
type(None).__name__: UnitType(),
bool.__name__: BoolType(),
}
Expand Down

0 comments on commit 3e4b547

Please sign in to comment.