Skip to content

Commit 367b4bd

Browse files
authored
Fix some deprecation warnings (#1301)
1 parent 6eacd74 commit 367b4bd

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

mathics/builtin/numpy_utils/with_numpy.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
# INTERNAL FUNCTIONS
1818
#
1919

20+
# Backward compatibility
21+
try:
22+
ast_Str = ast.Constant
23+
except AttributeError:
24+
ast_Str = lambda x: ast.Str(s=x)
25+
2026

2127
def _promote(x, shape):
2228
if isinstance(x, (int, float)):
@@ -396,9 +402,9 @@ def visit_If(self, node):
396402
test = node.test
397403
tests.append(test)
398404

399-
if type(test) == ast.Name:
405+
if type(test) is ast.Name:
400406
shapes.append(test)
401-
elif type(test) == ast.Compare:
407+
elif type(test) is ast.Compare:
402408
if isinstance(test.left, ast.Name):
403409
shapes.append(test.left)
404410
elif isinstance(test.right, ast.Name):
@@ -440,7 +446,7 @@ def visit_If(self, node):
440446
for test, value in zip(tests, (block.value for block in blocks)):
441447
elements = []
442448
if test == _else_case_id:
443-
elements.append(ast.Str(s=test))
449+
elements.append(ast_Str(test))
444450
else:
445451
elements.append(_create_ast_lambda([], test))
446452

mathics/core/parser/parser.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ def unescape_string(s: str) -> str:
6969
For example, '"a\\n\\c"' becomes 'a\nb\nc'
7070
"""
7171
assert len(s) >= 2 and s[0] == s[-1]
72+
# Special cases to avoid the Deprecation Warning
73+
if s in ('"\\!"', '"\\$"', '"\\W+"', '"\\d"'):
74+
return s[1:-1]
75+
7276
s = s.encode("raw_unicode_escape").decode("unicode_escape")
7377
return s[1:-1]
7478

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

917921
if self.is_inside_rowbox:
918-
# Hande function calls inside a RowBox.
922+
# Handle function calls inside a RowBox.
919923
result = Node("List", expr, String("["), *seq, String("]"))
920924
else:
921925
result = Node(expr, *seq)

0 commit comments

Comments
 (0)