Skip to content

Commit

Permalink
Fix some deprecation warnings (#1301)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatera authored Jan 18, 2025
1 parent 6eacd74 commit 367b4bd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 9 additions & 3 deletions mathics/builtin/numpy_utils/with_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
# INTERNAL FUNCTIONS
#

# Backward compatibility
try:
ast_Str = ast.Constant
except AttributeError:
ast_Str = lambda x: ast.Str(s=x)


def _promote(x, shape):
if isinstance(x, (int, float)):
Expand Down Expand Up @@ -396,9 +402,9 @@ def visit_If(self, node):
test = node.test
tests.append(test)

if type(test) == ast.Name:
if type(test) is ast.Name:
shapes.append(test)
elif type(test) == ast.Compare:
elif type(test) is ast.Compare:
if isinstance(test.left, ast.Name):
shapes.append(test.left)
elif isinstance(test.right, ast.Name):
Expand Down Expand Up @@ -440,7 +446,7 @@ def visit_If(self, node):
for test, value in zip(tests, (block.value for block in blocks)):
elements = []
if test == _else_case_id:
elements.append(ast.Str(s=test))
elements.append(ast_Str(test))
else:
elements.append(_create_ast_lambda([], test))

Expand Down
6 changes: 5 additions & 1 deletion mathics/core/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ def unescape_string(s: str) -> str:
For example, '"a\\n\\c"' becomes 'a\nb\nc'
"""
assert len(s) >= 2 and s[0] == s[-1]
# Special cases to avoid the Deprecation Warning
if s in ('"\\!"', '"\\$"', '"\\W+"', '"\\d"'):
return s[1:-1]

s = s.encode("raw_unicode_escape").decode("unicode_escape")
return s[1:-1]

Expand Down Expand Up @@ -915,7 +919,7 @@ def e_RawLeftBracket(self, expr, token: Token, p: int) -> Optional[Node]:
self.bracket_depth -= 1

if self.is_inside_rowbox:
# Hande function calls inside a RowBox.
# Handle function calls inside a RowBox.
result = Node("List", expr, String("["), *seq, String("]"))
else:
result = Node(expr, *seq)
Expand Down

0 comments on commit 367b4bd

Please sign in to comment.