Skip to content
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

Uncaught ValueError on inferring __getitem__ with nonsensical slices #1843

Closed
nelfin opened this issue Oct 20, 2022 · 0 comments · Fixed by #1844
Closed

Uncaught ValueError on inferring __getitem__ with nonsensical slices #1843

nelfin opened this issue Oct 20, 2022 · 0 comments · Fixed by #1844

Comments

@nelfin
Copy link
Contributor

nelfin commented Oct 20, 2022

Steps to reproduce

import astroid
node = astroid.extract_node("[][::0]")
print(next(node.infer()))

Current behavior

Traceback (most recent call last):
  File "repro.py", line 3, in <module>
    print(next(node.infer()))
  File ".../astroid/nodes/node_ng.py", line 169, in infer
    yield from self._infer(context=context, **kwargs)
  File ".../astroid/decorators.py", line 140, in raise_if_nothing_inferred
    yield next(generator)
  File ".../astroid/decorators.py", line 109, in wrapped
    for res in _func(node, context, **kwargs):
  File ".../astroid/inference.py", line 440, in infer_subscript
    assigned = value.getitem(index_value, context)
  File ".../astroid/nodes/node_classes.py", line 3499, in getitem
    return _container_getitem(self, self.elts, index, context=context)
  File ".../astroid/nodes/node_classes.py", line 232, in _container_getitem
    new_cls.elts = elts[index_slice]
ValueError: slice step cannot be zero

Originally spotted in pylint with a minimal reproducer like:

for _ in [][::0]:
    pass

Expected behavior

Uninferable

python -c "from astroid import __pkginfo__; print(__pkginfo__.version)" output

(venv) $ python -c "from astroid import __pkginfo__; print(__pkginfo__.version)"
2.13.0-dev0
(venv) $ git rev-parse HEAD
1a074cf66fc4fdb6714fac7afb14f9e7457cd704
nelfin added a commit to nelfin/astroid that referenced this issue Oct 20, 2022
nelfin added a commit to nelfin/astroid that referenced this issue Oct 20, 2022
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.12.13 milestone Oct 20, 2022
nelfin added a commit to nelfin/astroid that referenced this issue Nov 12, 2022
nelfin added a commit to nelfin/astroid that referenced this issue Nov 13, 2022
@jacobtylerwalls jacobtylerwalls removed this from the 2.12.13 milestone Nov 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants