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

Long arguments in a function cause a fatal error #8748

Closed
xiaxinmeng opened this issue Jun 7, 2023 · 2 comments · Fixed by pylint-dev/astroid#2228
Closed

Long arguments in a function cause a fatal error #8748

xiaxinmeng opened this issue Jun 7, 2023 · 2 comments · Fixed by pylint-dev/astroid#2228
Labels
Crash 💥 A bug that makes pylint crash Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Milestone

Comments

@xiaxinmeng
Copy link

Long arguments in a function cause a fatal error for pylint. I am not sure whether this is a bug for pylint, CPython also reports a MemoryError, but not a fatal error.

pylint_example.py

def f(*args): 
	return len(args)
f(*([0]*(2**32+1)))

The expected behavior:

There should be no fatal errors.

The actual output

>> pylint pylint_example.py
************* Module pylint_example
Desktop/pylint_example.py:14:3: C0303: Trailing whitespace (trailing-whitespace)
Desktop/pylint_example.py:17:13: C0303: Trailing whitespace (trailing-whitespace)
Desktop/pylint_example.py:18:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
Desktop/pylint_example.py:61:0: C0305: Trailing newlines (trailing-newlines)
Desktop/pylint_example.py:1:0: C0114: Missing module docstring (missing-module-docstring)
Desktop/pylint_example.py:17:0: C0116: Missing function or method docstring (missing-function-docstring)
Desktop/pylint_example.py:17:0: C0103: Function name "f" doesn't conform to snake_case naming style (invalid-name)
Exception on node <Call l.19 at 0x7f8b272a9e90> in file '/home/xxm/Desktop/pylint_example.py'
Traceback (most recent call last):
  File "/home/xxm/.local/lib/python3.11/site-packages/pylint/utils/ast_walker.py", line 91, in walk
    callback(astroid)
  File "/home/xxm/.local/lib/python3.11/site-packages/pylint/checkers/method_args.py", line 73, in visit_call
    self._check_missing_timeout(node)
  File "/home/xxm/.local/lib/python3.11/site-packages/pylint/checkers/method_args.py", line 83, in _check_missing_timeout
    call_site = arguments.CallSite.from_call(node)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xxm/.local/lib/python3.11/site-packages/astroid/arguments.py", line 67, in from_call
    return cls(callcontext, context=context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xxm/.local/lib/python3.11/site-packages/astroid/arguments.py", line 45, in __init__
    self._unpacked_args = self._unpack_args(args, context=context)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xxm/.local/lib/python3.11/site-packages/astroid/arguments.py", line 126, in _unpack_args
    inferred = safe_infer(arg.value, context=context)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xxm/.local/lib/python3.11/site-packages/astroid/helpers.py", line 171, in safe_infer
    value = next(inferit)
            ^^^^^^^^^^^^^
  File "/home/xxm/.local/lib/python3.11/site-packages/astroid/nodes/node_ng.py", line 179, in infer
    for i, result in enumerate(self._infer(context=context, **kwargs)):
  File "/home/xxm/.local/lib/python3.11/site-packages/astroid/decorators.py", line 71, in inner
    yield next(generator)
          ^^^^^^^^^^^^^^^
  File "/home/xxm/.local/lib/python3.11/site-packages/astroid/decorators.py", line 49, in wrapped
    for res in _func(node, context, **kwargs):
  File "/home/xxm/.local/lib/python3.11/site-packages/astroid/inference.py", line 567, in _filter_operation_errors
    for result in infer_callable(self, context):
  File "/home/xxm/.local/lib/python3.11/site-packages/astroid/inference.py", line 987, in _infer_binop
    yield from _infer_binary_operation(lhs, rhs, self, context, _get_binop_flow)
  File "/home/xxm/.local/lib/python3.11/site-packages/astroid/inference.py", line 936, in _infer_binary_operation
    results = list(method())
              ^^^^^^^^^^^^^^
  File "/home/xxm/.local/lib/python3.11/site-packages/astroid/decorators.py", line 71, in inner
    yield next(generator)
          ^^^^^^^^^^^^^^^
  File "/home/xxm/.local/lib/python3.11/site-packages/astroid/protocols.py", line 224, in tl_infer_binary_op
    yield _multiply_seq_by_int(self, opnode, other, context)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xxm/.local/lib/python3.11/site-packages/astroid/protocols.py", line 175, in _multiply_seq_by_int
    node.elts = list(filtered_elts) * other.value
                ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
MemoryError
Desktop/pylint_example.py:1:0: F0002: /home/xxm/Desktop/pylint_example.py: Fatal error while checking '/home/xxm/Desktop/pylint_example.py'. Please open an issue in our bug tracker so we address this. There is a pre-filled template that you can use in '/home/xxm/.cache/pylint/pylint-crash-2023-06-07-13-30-48.txt'. (astroid-error)

------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)

Test Environment

pylint 3.0.0b1
astroid 3.0.0a5-dev0
Python 3.11.3
Ubuntu 18.04

@Pierre-Sassoulas Pierre-Sassoulas added Crash 💥 A bug that makes pylint crash Needs PR This issue is accepted, sufficiently specified and now needs an implementation labels Jun 7, 2023
@jacobtylerwalls
Copy link
Member

Thanks for the report. safe_infer could catch MemoryError, or we could add some sort of clever guard like #6745, but I would be weary of accumulating too many clever guards all over.

@jacobtylerwalls
Copy link
Member

One more clever guard is okay. See pylint-dev/astroid#2228

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Crash 💥 A bug that makes pylint crash Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants