Skip to content

Commit edbfbb9

Browse files
committed
Replace deprecated Str, Num with Constant, fixes #524
Signed-off-by: Tim Paine <[email protected]>
1 parent a39ecdf commit edbfbb9

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

csp/impl/wiring/base_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def _extract_outputs_from_body(self, body):
261261
lineno = None
262262
for i, body_item in enumerate(body):
263263
lineno = body_item.lineno
264-
if isinstance(body_item, ast.Expr) and isinstance(body_item.value, ast.Str):
264+
if isinstance(body_item, ast.Expr) and isinstance(body_item.value, ast.Constant):
265265
# last_doc_string_item = i
266266
continue
267267
break

csp/impl/wiring/node_parser.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ def _validate_return_statements(self):
678678
def _parse_special_blocks(self, body):
679679
# skip doc string
680680
for index, node in enumerate(body):
681-
if not isinstance(node, ast.Expr) or not isinstance(node.value, ast.Str):
681+
if not isinstance(node, ast.Expr) or not isinstance(node.value, ast.Constant):
682682
break
683683

684684
last_special_block = None
@@ -766,7 +766,7 @@ def _parse_impl(self):
766766
node_proxy = [
767767
ast.Assign(
768768
targets=[self._node_proxy_expr(ast.Store())],
769-
value=ast.Tuple(elts=[ast.Str(self._NODE_P_VARNAME), ast.Num(n=0)], ctx=ast.Load()),
769+
value=ast.Tuple(elts=[ast.Constant(self._NODE_P_VARNAME), ast.Constant(0)], ctx=ast.Load()),
770770
)
771771
] # '#nodep'
772772
ts_in_proxies = []
@@ -780,7 +780,7 @@ def _parse_impl(self):
780780
ast.Assign(
781781
targets=[proxy],
782782
value=ast.Tuple(
783-
elts=[ast.Str(s=self._INPUT_PROXY_VARNAME), ast.Num(n=inp.ts_idx)], ctx=ast.Load()
783+
elts=[ast.Constant(self._INPUT_PROXY_VARNAME), ast.Constant(inp.ts_idx)], ctx=ast.Load()
784784
),
785785
)
786786
)
@@ -789,7 +789,7 @@ def _parse_impl(self):
789789
ast.Assign(
790790
targets=[ast.Name(id=inp.name, ctx=ast.Store())],
791791
value=ast.Tuple(
792-
elts=[ast.Str(s=self._INPUT_VAR_VARNAME), ast.Num(n=inp.ts_idx)], ctx=ast.Load()
792+
elts=[ast.Constant(self._INPUT_VAR_VARNAME), ast.Num(n=inp.ts_idx)], ctx=ast.Load()
793793
),
794794
)
795795
)
@@ -801,7 +801,7 @@ def _parse_impl(self):
801801
ast.Assign(
802802
targets=[ast.Name(id=name, ctx=ast.Store())],
803803
value=ast.Tuple(
804-
elts=[ast.Str(s=self._OUTPUT_PROXY_VARNAME), ast.Num(n=output.ts_idx)], ctx=ast.Load()
804+
elts=[ast.Constant(self._OUTPUT_PROXY_VARNAME), ast.Constant(output.ts_idx)], ctx=ast.Load()
805805
),
806806
)
807807
)

csp/impl/wiring/numba_node_parser.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,8 @@ def _parse_state(self, node):
6363

6464
for kwd in call.keywords:
6565
if kwd.arg not in self._state_types:
66-
if isinstance(kwd.value, ast.Num):
67-
self._state_types[kwd.arg] = type(kwd.value.n)
68-
elif isinstance(kwd.value, ast.Str):
69-
self._state_types[kwd.arg] = str
70-
elif isinstance(kwd.value, ast.NameConstant) and isinstance(kwd.value.value, bool):
71-
self._state_types[kwd.arg] = bool
66+
if isinstance(kwd.value, ast.Constant):
67+
self._state_types[kwd.arg] = type(kwd.value)
7268
else:
7369
raise CspParseError(
7470
f"Unable to resolve type of state variable {kwd.arg}, explicit type must be provided in numba_node decorator",
@@ -186,12 +182,15 @@ def _create_state_class(
186182
new_args.append(new_arg)
187183

188184
cls_field_types = [
189-
ast.Tuple(elts=[ast.Str(s=arg.arg), ast.Name(id=self.get_arg_type_var_name(arg.arg), ctx=l_ctx)], ctx=l_ctx)
185+
ast.Tuple(
186+
elts=[ast.Constant(arg.arg), ast.Name(id=self.get_arg_type_var_name(arg.arg), ctx=l_ctx)], ctx=l_ctx
187+
)
190188
for arg in self.get_non_ts_args()
191189
]
192190
cls_field_types += [
193191
ast.Tuple(
194-
elts=[ast.Str(s=state_var), ast.Name(id=self.get_state_type_var_name(state_var), ctx=l_ctx)], ctx=l_ctx
192+
elts=[ast.Constant(state_var), ast.Name(id=self.get_state_type_var_name(state_var), ctx=l_ctx)],
193+
ctx=l_ctx,
195194
)
196195
for state_var in state_vars
197196
]

0 commit comments

Comments
 (0)