Skip to content

Commit

Permalink
update for Python 3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
caterinaurban committed Nov 7, 2023
1 parent c19ebbf commit 883ee1f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/lyra/frontend/cfg_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,29 @@ def generic_visit(self, node, *args, **kwargs):

# Literals

# noinspection PyUnusedLocal
def visit_Constant(self, node, types=None, libraries=None, typ=None, fname=''):
pp = ProgramPoint(node.lineno, node.col_offset)
if isinstance(node.value, bool):
expr = Literal(BooleanLyraType(), str(node.value))
return LiteralEvaluation(pp, expr)
elif isinstance(node.value, int):
expr = Literal(IntegerLyraType(), str(node.n))
return LiteralEvaluation(pp, expr)
elif isinstance(node.value, float):
expr = Literal(FloatLyraType(), str(node.n))
return LiteralEvaluation(pp, expr)
elif isinstance(node.value, str):
expr = Literal(StringLyraType(), node.s)
return LiteralEvaluation(pp, expr)
raise NotImplementedError(f"Num of type {node.n.__class__.__name__} is unsupported!")

# noinspection PyUnusedLocal
def visit_Num(self, node, types=None, libraries=None, typ=None, fname=''):
"""Visitor function for a number (integer, float, or complex).
The n attribute stores the value, already converted to the relevant type."""
import warnings
warnings.warn('Class deprecated since Python 3.8', DeprecationWarning)
pp = ProgramPoint(node.lineno, node.col_offset)
if isinstance(node.n, int):
expr = Literal(IntegerLyraType(), str(node.n))
Expand All @@ -345,6 +364,8 @@ def visit_Num(self, node, types=None, libraries=None, typ=None, fname=''):
# noinspection PyMethodMayBeStatic, PyUnusedLocal
def visit_Str(self, node, types=None, libraries=None, typ=None, fname=''):
"""Visitor function for a string. The s attribute stores the value."""
import warnings
warnings.warn('Class deprecated since Python 3.8', DeprecationWarning)
pp = ProgramPoint(node.lineno, node.col_offset)
expr = Literal(StringLyraType(), node.s)
return LiteralEvaluation(pp, expr)
Expand Down Expand Up @@ -441,6 +462,8 @@ def visit_Dict(self, node, types=None, libraries=None, typ=None, fname=''):
def visit_NameConstant(self, node, types=None, libraries=None, typ=None, fname=''):
"""Visitor function for True, False or None.
The value attribute stores the constant."""
import warnings
warnings.warn('Class deprecated since Python 3.8', DeprecationWarning)
if isinstance(node.value, bool):
pp = ProgramPoint(node.lineno, node.col_offset)
expr = Literal(BooleanLyraType(), str(node.value))
Expand Down

0 comments on commit 883ee1f

Please sign in to comment.