Skip to content

Commit

Permalink
Fix uncaught ValueError in infer_getitem with zero-step slices
Browse files Browse the repository at this point in the history
  • Loading branch information
nelfin committed Oct 20, 2022
1 parent 5caa47f commit 786ffe4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions astroid/inference.py
Expand Up @@ -27,6 +27,7 @@
AstroidError,
AstroidIndexError,
AstroidTypeError,
AstroidValueError,
AttributeInferenceError,
InferenceError,
NameInferenceError,
Expand Down Expand Up @@ -441,6 +442,7 @@ def infer_subscript(
except (
AstroidTypeError,
AstroidIndexError,
AstroidValueError,
AttributeInferenceError,
AttributeError,
) as exc:
Expand Down
8 changes: 8 additions & 0 deletions astroid/nodes/node_classes.py
Expand Up @@ -22,6 +22,7 @@
from astroid.exceptions import (
AstroidIndexError,
AstroidTypeError,
AstroidValueError,
InferenceError,
NoDefault,
ParentMissingError,
Expand Down Expand Up @@ -234,6 +235,13 @@ def _container_getitem(instance, elts, index, context=None):
return new_cls
if isinstance(index, Const):
return elts[index.value]
except ValueError as exc:
raise AstroidValueError(
message="Slice {index!r} cannot index container",
node=instance,
index=index,
context=context
) from exc
except IndexError as exc:
raise AstroidIndexError(
message="Index {index!s} out of range",
Expand Down

0 comments on commit 786ffe4

Please sign in to comment.