Skip to content

Commit

Permalink
add coverage pragmas in parse_index for code paths unused in cpy38/39
Browse files Browse the repository at this point in the history
  • Loading branch information
telamonian committed Oct 23, 2020
1 parent 3733175 commit 8345caa
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions ndindex/ndindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ def parse_index(node_or_string):
node_or_string = node_or_string.slice

def _raise_malformed_node(node):
raise ValueError(f'malformed node or string: {node!r}')
raise ValueError(f'malformed node or string: {node!r}, {ast.dump(node)!r}')
def _raise_nested_tuple_node(node):
raise ValueError(f'tuples inside of tuple indices are not supported: {node!r}')
raise ValueError(f'tuples inside of tuple indices are not supported: {node!r}, {ast.dump(node)!r}')

# from cpy37, should work until they remove ast.Num (not until cpy310)
def _convert_num(node):
Expand All @@ -101,7 +101,7 @@ def _convert_num(node):
return node.value
elif isinstance(node, ast.Num):
# ast.Num was removed from ast grammar in cpy38
return node.n
return node.n # pragma: no cover
_raise_malformed_node(node)
def _convert_signed_num(node):
if isinstance(node, ast.UnaryOp) and isinstance(node.op, (ast.UAdd, ast.USub)):
Expand Down Expand Up @@ -141,11 +141,11 @@ def _convert(node):
return ...
elif isinstance(node, ast.Index):
# ast.Index was removed from ast grammar in cpy39
return _convert(node.value)
return _convert(node.value) # pragma: no cover
elif isinstance(node, ast.ExtSlice):
# ast.ExtSlice was removed from ast grammar in cpy39
_nested_tuple_guard()
return tuple(map(_convert, node.dims))
_nested_tuple_guard() # pragma: no cover
return tuple(map(_convert, node.dims)) # pragma: no cover

return _convert_signed_num(node)
return ndindex(_convert(node_or_string))
Expand Down

0 comments on commit 8345caa

Please sign in to comment.