Skip to content

Commit 3afbece

Browse files
Fixing some AST deprecationwarnings
Because ast.s, ast.n and ast.Str will be deprecated from python 3.14
1 parent 3f4168c commit 3afbece

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

parcels/compilation/codegenerator.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def visit_Call(self, node):
346346
convert = True
347347
if "applyConversion" in node.keywords:
348348
k = node.keywords["applyConversion"]
349-
if isinstance(k, ast.NameConstant):
349+
if isinstance(k, ast.Constant):
350350
convert = k.value
351351

352352
# convert args to Index(Tuple(*args))
@@ -364,7 +364,7 @@ def visit_Call(self, node):
364364
convert = True
365365
if "applyConversion" in node.keywords:
366366
k = node.keywords["applyConversion"]
367-
if isinstance(k, ast.NameConstant):
367+
if isinstance(k, ast.Constant):
368368
convert = k.value
369369

370370
# convert args to Index(Tuple(*args))
@@ -463,8 +463,7 @@ def _check_FieldSamplingArguments(ccode):
463463
def visit_FunctionDef(self, node):
464464
# Generate "ccode" attribute by traversing the Python AST
465465
for stmt in node.body:
466-
if not (hasattr(stmt, 'value') and type(stmt.value) is ast.Str): # ignore docstrings
467-
self.visit(stmt)
466+
self.visit(stmt)
468467

469468
# Create function declaration and argument list
470469
decl = c.Static(c.DeclSpecifier(c.Value("StatusCode", node.name), spec='inline'))
@@ -492,7 +491,7 @@ def visit_FunctionDef(self, node):
492491
body += [c.Statement(f"particles->{coord}[pnum] = particles->{coord}_nextloop[pnum]")]
493492
body += [c.Statement("particles->time[pnum] = particles->time_nextloop[pnum]")]
494493

495-
body += [stmt.ccode for stmt in node.body if not (hasattr(stmt, 'value') and type(stmt.value) is ast.Str)]
494+
body += [stmt.ccode for stmt in node.body]
496495

497496
for coord in ['lon', 'lat', 'depth']:
498497
body += [c.Statement(f"particles->{coord}_nextloop[pnum] = particles->{coord}[pnum] + particle_d{coord}")]
@@ -878,14 +877,14 @@ def visit_Print(self, node):
878877
node.ccode = c.Statement(f'printf("{stat}\\n", {vars})')
879878

880879
def visit_Constant(self, node):
881-
if node.s == 'parcels_customed_Cfunc_pointer_args':
882-
node.ccode = node.s
883-
elif isinstance(node.s, str):
880+
if node.value == 'parcels_customed_Cfunc_pointer_args':
881+
node.ccode = node.value
882+
elif isinstance(node.value, str):
884883
node.ccode = '' # skip strings from docstrings or comments
885-
elif isinstance(node.s, bool):
886-
node.ccode = "1" if node.s is True else "0"
884+
elif isinstance(node.value, bool):
885+
node.ccode = "1" if node.value is True else "0"
887886
else:
888-
node.ccode = str(node.n)
887+
node.ccode = str(node.value)
889888

890889

891890
class LoopGenerator:

0 commit comments

Comments
 (0)