Skip to content

Commit

Permalink
Make net parser work consistently on all supported versions of Python
Browse files Browse the repository at this point in the history
  • Loading branch information
Higgcz committed Nov 23, 2022
1 parent 7559abf commit 9174017
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/evotorch/neuroevolution/net/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,10 @@ def get_from_constant(name, index):
index = node.slice
if isinstance(index, ast.Index):
index = index.value
elif isinstance(index, ast.Constant):
pass # Do nothing
else:

# Note: ast.Num is a subclass of ast.Constant in Python 3.8 and later.
# To support Python 3.7 and earlier, we need to check for both.
if not isinstance(index, (ast.Constant, ast.Num)):
fail(f"Expected a simple indexing operation, but got a {type(index).__name__}.", index)

index = literal_eval(index)
Expand Down

0 comments on commit 9174017

Please sign in to comment.