Skip to content

Commit

Permalink
refactor[lang]: remove translated fields for constant nodes (#4287)
Browse files Browse the repository at this point in the history
This commit removes the `.s` field from the AST for string-like
constants. These were deprecated in the Python AST in 3.8; we no longer
need to translate them for our AST.

---------

Co-authored-by: Charles Cooper <[email protected]>
  • Loading branch information
tserg and charles-cooper authored Oct 13, 2024
1 parent 12e5ba9 commit 61f7f4e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 27 deletions.
12 changes: 0 additions & 12 deletions vyper/ast/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,6 @@ class DocStr(VyperNode):
"""

__slots__ = ("value",)
_translated_fields = {"s": "value"}


class arguments(VyperNode):
Expand Down Expand Up @@ -887,7 +886,6 @@ def bytes_value(self):

class Str(Constant):
__slots__ = ()
_translated_fields = {"s": "value"}

def validate(self):
for c in self.value:
Expand All @@ -897,7 +895,6 @@ def validate(self):

class Bytes(Constant):
__slots__ = ()
_translated_fields = {"s": "value"}

def __init__(self, parent: Optional["VyperNode"] = None, **kwargs: dict):
super().__init__(parent, **kwargs)
Expand All @@ -911,14 +908,9 @@ def to_dict(self):
ast_dict["value"] = f"0x{self.value.hex()}"
return ast_dict

@property
def s(self):
return self.value


class HexBytes(Constant):
__slots__ = ()
_translated_fields = {"s": "value"}

def __init__(self, parent: Optional["VyperNode"] = None, **kwargs: dict):
super().__init__(parent, **kwargs)
Expand All @@ -930,10 +922,6 @@ def to_dict(self):
ast_dict["value"] = f"0x{self.value.hex()}"
return ast_dict

@property
def s(self):
return self.value


class List(ExprNode):
__slots__ = ("elements",)
Expand Down
19 changes: 4 additions & 15 deletions vyper/ast/nodes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ class ExprNode(VyperNode):
class Constant(ExprNode):
value: Any = ...

class Num(Constant):
@property
def n(self): ...
class Num(Constant): ...

class Int(Num):
value: int = ...
Expand All @@ -123,18 +121,9 @@ class Hex(Num):
@property
def n_bytes(self): ...

class Str(Constant):
@property
def s(self): ...

class Bytes(Constant):
@property
def s(self): ...

class HexBytes(Constant):
@property
def s(self): ...

class Str(Constant): ...
class Bytes(Constant): ...
class HexBytes(Constant): ...
class NameConstant(Constant): ...
class Ellipsis(Constant): ...

Expand Down

0 comments on commit 61f7f4e

Please sign in to comment.