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

[FIX] pylint_odoo: Fix AstroidSyntaxError #509

Merged
merged 1 commit into from
Dec 19, 2024

Conversation

moylop260
Copy link
Collaborator

@moylop260 moylop260 commented Dec 19, 2024

Using the following code:

"%s".lstrip() % "value"

binop.left is returning the structure different if the method is called method("%s" % value) and "%s".method() % value

So the code above is malformed '%s'.lstrip( % 'value')

Raising the following error:

Traceback (most recent call last):
  File "site-packages/astroid/builder.py", line 181, in _data_build
    node, parser_module = _parse_string(
                          ^^^^^^^^^^^^^^
  File "site-packages/astroid/builder.py", line 480, in _parse_string
    parsed = parser_module.parse(
             ^^^^^^^^^^^^^^^^^^^^
  File "site-packages/astroid/_ast.py", line 30, in parse
    return ast.parse(string, type_comments=type_comments)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "python3.11/ast.py", line 50, in parse
    return compile(source, filename, mode, flags,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<unknown>", line 1
    '%s'.lstrip( % 'value')
                 ^
SyntaxError: invalid syntax

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

Traceback (most recent call last):
  File "site-packages/pylint/lint/pylinter.py", line 830, in _check_file
    check_astroid_module(ast_node)
  File "site-packages/pylint/lint/pylinter.py", line 1016, in check_astroid_module
    retval = self._check_astroid_module(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "site-packages/pylint/lint/pylinter.py", line 1068, in _check_astroid_module
    walker.walk(node)
  File "site-packages/pylint/utils/ast_walker.py", line 94, in walk
    self.walk(child)
  File "site-packages/pylint/utils/ast_walker.py", line 94, in walk
    self.walk(child)
  File "site-packages/pylint/utils/ast_walker.py", line 94, in walk
    self.walk(child)
  [Previous line repeated 1 more time]
  File "site-packages/pylint/utils/ast_walker.py", line 91, in walk
    callback(astroid)
  File "pylint_odoo/checkers/custom_logging.py", line 91, in visit_binop
    self.visit_call(self.transform_binop2call(node))
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pylint_odoo/checkers/custom_logging.py", line 82, in transform_binop2call
    new_node = builder.extract_node(new_code)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "site-packages/astroid/builder.py", line 446, in extract_node
    tree = parse(code, module_name=module_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "site-packages/astroid/builder.py", line 303, in parse
    return builder.string_build(code, modname=module_name, path=path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "site-packages/astroid/builder.py", line 151, in string_build
    module, builder = self._data_build(data, modname, path)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "site-packages/astroid/builder.py", line 185, in _data_build
    raise AstroidSyntaxError(
astroid.exceptions.AstroidSyntaxError: Parsing Python code failed:
invalid syntax (<unknown>, line 1)

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

Traceback (most recent call last):
  File "python3.11/concurrent/futures/process.py", line 261, in _process_worker
    r = call_item.fn(*call_item.args, **call_item.kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "python3.11/concurrent/futures/process.py", line 210, in _process_chunk
    return [fn(*args) for args in chunk]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "python3.11/concurrent/futures/process.py", line 210, in <listcomp>
    return [fn(*args) for args in chunk]
            ^^^^^^^^^
  File "site-packages/pylint/lint/parallel.py", line 79, in _worker_check_single_file
    _worker_linter.check_single_file_item(file_item)
  File "site-packages/pylint/lint/pylinter.py", line 739, in check_single_file_item
    self._check_file(self.get_ast, check_astroid_module, file)
  File "site-packages/pylint/lint/pylinter.py", line 832, in _check_file
    raise astroid.AstroidError from e
astroid.exceptions.AstroidError
"""

The above exception was the direct cause of the following exception:
tests/test_main.py:430: in test_180_jobs
    pylint_res = self.run_pylint(self.paths_modules, verbose=True)
tests/test_main.py:120: in run_pylint
    self._run_pylint(cmd, f_dummy, reporter=reporter)
tests/test_main.py:132: in _run_pylint
    Run(args, reporter=reporter)
pylint/testutils/_run.py:41: in __init__
    super().__init__(args, reporter, exit)
pylint/lint/run.py:211: in __init__
    linter.check(args)
pylint/lint/pylinter.py:678: in check
    check_parallel(
pylint/lint/parallel.py:153: in check_parallel
    for (
python3.11/concurrent/futures/process.py:620: in _chain_from_iterable_of_lists
    for element in iterable:
python3.11/concurrent/futures/_base.py:619: in result_iterator
    yield _result_or_cancel(fs.pop())
python3.11/concurrent/futures/_base.py:317: in _result_or_cancel
    return fut.result(timeout)
python3.11/concurrent/futures/_base.py:456: in result
    return self.__get_result()
python3.11/concurrent/futures/_base.py:[401](https://github.com/OCA/pylint-odoo/actions/runs/12407071620/job/34636504075#step:7:402): in __get_result
    raise self._exception
E   astroid.exceptions.AstroidError

@moylop260 moylop260 self-assigned this Dec 19, 2024
@moylop260 moylop260 changed the title DRAFT: [FIX] pylint_odoo: Fix AstroidSyntaxError [FIX] pylint_odoo: Fix AstroidSyntaxError Dec 19, 2024
@moylop260 moylop260 force-pushed the fix-binop-moy branch 2 times, most recently from 64fc337 to dba1183 Compare December 19, 2024 18:16
There is a corner case where pylint_odoo could raise errors

It was considered in the unittest and it was already fixed
@moylop260 moylop260 merged commit fc39ad4 into OCA:main Dec 19, 2024
25 of 26 checks passed
@moylop260 moylop260 deleted the fix-binop-moy branch December 19, 2024 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant