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

"TypeError: 'UninferableBase' object is not iterable" when inferring random.sample code #2518

Open
correctmost opened this issue Aug 26, 2024 · 1 comment

Comments

@correctmost
Copy link
Contributor

Steps to reproduce

The following code triggers a TypeError in astroid:

a=random.sample(1*[b], 1)

This bug was discovered by OSS-Fuzz:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=64604 (report not public yet)

Current behavior

Exception on node <AssignName.a l.1 at 0x7bc0fed59340> in file 'corpus/a.py'
Traceback (most recent call last):
  File "pylint/pylint/checkers/utils.py", line 1365, in safe_infer
    value = next(infer_gen)
            ^^^^^^^^^^^^^^^
  File "astroid/astroid/nodes/node_ng.py", line 147, in infer
    for result in self._explicit_inference(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "astroid/astroid/inference_tip.py", line 70, in inner
    raise e from None
  File "astroid/astroid/inference_tip.py", line 66, in inner
    func(node, context, **kwargs)
  File "astroid/astroid/brain/brain_random.py", line 84, in infer_random_sample
    _clone_node_with_lineno(elt, parent=new_node, lineno=new_node.lineno)
  File "astroid/astroid/brain/brain_random.py", line 41, in _clone_node_with_lineno
    postinit_params = {param: getattr(node, param) for param in _astroid_fields}
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'UninferableBase' object is not iterable

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "pylint/pylint/utils/ast_walker.py", line 91, in walk
    callback(astroid)
  File "pylint/pylint/checkers/base/name_checker/checker.py", line 423, in visit_assignname
    inferred_assign_type = utils.safe_infer(assign_type.value)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pylint/pylint/checkers/utils.py", line 1369, in safe_infer
    raise AstroidError from e
astroid.exceptions.AstroidError

Expected behavior

No crash

Version

d8dbc46

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants
@Pierre-Sassoulas @correctmost and others