Skip to content

Commit

Permalink
remove is_literal
Browse files Browse the repository at this point in the history
  • Loading branch information
tserg committed Nov 12, 2023
1 parent d4d598a commit 8e8f204
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions vyper/semantics/types/bytestrings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

from vyper import ast as vy_ast
from vyper.abi_types import ABI_Bytes, ABI_String, ABIType
from vyper.exceptions import CompilerPanic, StructureException, UnexpectedNodeType, UnexpectedValue
Expand Down Expand Up @@ -25,9 +27,8 @@ class _BytestringT(VyperType):
_as_hashmap_key = True
_equality_attrs = ("_length",)
_is_bytestring: bool = True
_is_literal: bool = False

def __init__(self, length: int = 0) -> None:
def __init__(self, length: Optional[int] = None) -> None:
super().__init__()

self._length = length
Expand All @@ -40,6 +41,8 @@ def length(self):
"""
Property method used to check the length of a type.
"""
if self._length is None:
return 0
return self._length

@property
Expand Down Expand Up @@ -72,13 +75,13 @@ def compare_type(self, other):

# when comparing two literals, or two bytestrings of non-zero lengths,
# ensure that the other length fits within self
if (self._is_literal and other._is_literal) or (self._length and other._length):
if self._length is not None and other._length is not None:
return self._length >= other._length

# relax typechecking if length has not been set for other type
# (e.g. JSON ABI import, `address.code`) so that it can be updated in
# annotation phase
if self._length:
if self._length is not None:
return True

# if both are non-literals and zero length, then the bytestring length
Expand Down Expand Up @@ -108,7 +111,6 @@ def from_literal(cls, node: vy_ast.Constant) -> "_BytestringT":
if not isinstance(node, cls._valid_literal):
raise UnexpectedNodeType(f"Not a {cls._id}: {node}")
t = cls(len(node.value))
t._is_literal = True
return t


Expand Down

0 comments on commit 8e8f204

Please sign in to comment.