Skip to content

Replace deprecated Str, Num with Constant, fixes #524 #525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion csp/impl/wiring/base_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def _extract_outputs_from_body(self, body):
lineno = None
for i, body_item in enumerate(body):
lineno = body_item.lineno
if isinstance(body_item, ast.Expr) and isinstance(body_item.value, ast.Str):
if isinstance(body_item, ast.Expr) and isinstance(body_item.value, ast.Constant):
# last_doc_string_item = i
continue
break
Expand Down
10 changes: 5 additions & 5 deletions csp/impl/wiring/node_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ def _validate_return_statements(self):
def _parse_special_blocks(self, body):
# skip doc string
for index, node in enumerate(body):
if not isinstance(node, ast.Expr) or not isinstance(node.value, ast.Str):
if not isinstance(node, ast.Expr) or not isinstance(node.value, ast.Constant):
break

last_special_block = None
Expand Down Expand Up @@ -766,7 +766,7 @@ def _parse_impl(self):
node_proxy = [
ast.Assign(
targets=[self._node_proxy_expr(ast.Store())],
value=ast.Tuple(elts=[ast.Str(self._NODE_P_VARNAME), ast.Num(n=0)], ctx=ast.Load()),
value=ast.Tuple(elts=[ast.Constant(self._NODE_P_VARNAME), ast.Constant(0)], ctx=ast.Load()),
)
] # '#nodep'
ts_in_proxies = []
Expand All @@ -780,7 +780,7 @@ def _parse_impl(self):
ast.Assign(
targets=[proxy],
value=ast.Tuple(
elts=[ast.Str(s=self._INPUT_PROXY_VARNAME), ast.Num(n=inp.ts_idx)], ctx=ast.Load()
elts=[ast.Constant(self._INPUT_PROXY_VARNAME), ast.Constant(inp.ts_idx)], ctx=ast.Load()
),
)
)
Expand All @@ -789,7 +789,7 @@ def _parse_impl(self):
ast.Assign(
targets=[ast.Name(id=inp.name, ctx=ast.Store())],
value=ast.Tuple(
elts=[ast.Str(s=self._INPUT_VAR_VARNAME), ast.Num(n=inp.ts_idx)], ctx=ast.Load()
elts=[ast.Constant(self._INPUT_VAR_VARNAME), ast.Num(n=inp.ts_idx)], ctx=ast.Load()
),
)
)
Expand All @@ -801,7 +801,7 @@ def _parse_impl(self):
ast.Assign(
targets=[ast.Name(id=name, ctx=ast.Store())],
value=ast.Tuple(
elts=[ast.Str(s=self._OUTPUT_PROXY_VARNAME), ast.Num(n=output.ts_idx)], ctx=ast.Load()
elts=[ast.Constant(self._OUTPUT_PROXY_VARNAME), ast.Constant(output.ts_idx)], ctx=ast.Load()
),
)
)
Expand Down
15 changes: 7 additions & 8 deletions csp/impl/wiring/numba_node_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,8 @@ def _parse_state(self, node):

for kwd in call.keywords:
if kwd.arg not in self._state_types:
if isinstance(kwd.value, ast.Num):
self._state_types[kwd.arg] = type(kwd.value.n)
elif isinstance(kwd.value, ast.Str):
self._state_types[kwd.arg] = str
elif isinstance(kwd.value, ast.NameConstant) and isinstance(kwd.value.value, bool):
self._state_types[kwd.arg] = bool
if isinstance(kwd.value, ast.Constant):
self._state_types[kwd.arg] = type(kwd.value)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be good to sanity check this

else:
raise CspParseError(
f"Unable to resolve type of state variable {kwd.arg}, explicit type must be provided in numba_node decorator",
Expand Down Expand Up @@ -186,12 +182,15 @@ def _create_state_class(
new_args.append(new_arg)

cls_field_types = [
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)
ast.Tuple(
elts=[ast.Constant(arg.arg), ast.Name(id=self.get_arg_type_var_name(arg.arg), ctx=l_ctx)], ctx=l_ctx
)
for arg in self.get_non_ts_args()
]
cls_field_types += [
ast.Tuple(
elts=[ast.Str(s=state_var), ast.Name(id=self.get_state_type_var_name(state_var), ctx=l_ctx)], ctx=l_ctx
elts=[ast.Constant(state_var), ast.Name(id=self.get_state_type_var_name(state_var), ctx=l_ctx)],
ctx=l_ctx,
)
for state_var in state_vars
]
Expand Down
Loading