Skip to content

Gracefully handle invalid ‘ignore-paths’ regex crash #9680

Description

@RaulWCosta

Bug description

Pylint fails with an error when executed on the following snippet:

import itertools

for i, j in enumerate(itertools.repeat(1)):
    if i == 10:
        break
    print(j)

Configuration

[tool.pylint.master]
extension-pkg-whitelist = [
  'numpy,nose,nose.tools,numpy.testing,pathlib.PurePath,pathlib.PosixPath,pathlib.Path',
]
output-format = ['colorized']
ignore-paths = ['project/tooling_context/**']

[tool.pylint.'MESSAGES CONTROL']
disable = [
  'C0412,C1801,duplicate-code,E0402,W0611,W1116,W1203,W1309,fixme,import-error,invalid-name,logging-format-interpolation,missing-docstring,no-else-return,no-member,protected-access,too-few-public-methods,trailing-comma-tuple',
]

[tool.pylint.'DESIGN']
max-args = 10
max-attributes = 14

[tool.pylint.'TYPECHECK']
ignored-modules = ['numpy, numpy.testing, pandas']
ignored-classes = ['numpy, numpy.testing, pandas']

[tool.pylint.'BASIC']
good-names = ['X, x, y']

[tool.pylint.'FORMAT']
max-line-length = 88

Command used

pylint -rn -sn --rcfile=pyproject.toml teste.py

Pylint output

Traceback (most recent call last):
  File "/Users/Raul_Costa/.pyenv/versions/project/bin/pylint", line 8, in <module>
    sys.exit(run_pylint())
  File "/Users/Raul_Costa/.pyenv/versions/3.10.13/envs/project/lib/python3.10/site-packages/pylint/__init__.py", line 34, in run_pylint
    PylintRun(argv or sys.argv[1:])
  File "/Users/Raul_Costa/.pyenv/versions/3.10.13/envs/project/lib/python3.10/site-packages/pylint/lint/run.py", line 162, in __init__
    args = _config_initialization(
  File "/Users/Raul_Costa/.pyenv/versions/3.10.13/envs/project/lib/python3.10/site-packages/pylint/config/config_initialization.py", line 66, in _config_initialization
    linter._parse_configuration_file(config_args)
  File "/Users/Raul_Costa/.pyenv/versions/3.10.13/envs/project/lib/python3.10/site-packages/pylint/config/arguments_manager.py", line 212, in _parse_configuration_file
    self.config, parsed_args = self._arg_parser.parse_known_args(
  File "/Users/Raul_Costa/.pyenv/versions/3.10.13/lib/python3.10/argparse.py", line 1866, in parse_known_args
    namespace, args = self._parse_known_args(args, namespace)
  File "/Users/Raul_Costa/.pyenv/versions/3.10.13/lib/python3.10/argparse.py", line 2079, in _parse_known_args
    start_index = consume_optional(start_index)
  File "/Users/Raul_Costa/.pyenv/versions/3.10.13/lib/python3.10/argparse.py", line 2019, in consume_optional
    take_action(action, args, option_string)
  File "/Users/Raul_Costa/.pyenv/versions/3.10.13/lib/python3.10/argparse.py", line 1927, in take_action
    argument_values = self._get_values(action, argument_strings)
  File "/Users/Raul_Costa/.pyenv/versions/3.10.13/lib/python3.10/argparse.py", line 2462, in _get_values
    value = self._get_value(action, arg_string)
  File "/Users/Raul_Costa/.pyenv/versions/3.10.13/lib/python3.10/argparse.py", line 2495, in _get_value
    result = type_func(arg_string)
  File "/Users/Raul_Costa/.pyenv/versions/3.10.13/envs/project/lib/python3.10/site-packages/pylint/config/argument.py", line 127, in _regexp_paths_csv_transfomer
    re.compile(
  File "/Users/Raul_Costa/.pyenv/versions/3.10.13/lib/python3.10/re.py", line 251, in compile
    return _compile(pattern, flags)
  File "/Users/Raul_Costa/.pyenv/versions/3.10.13/lib/python3.10/re.py", line 303, in _compile
    p = sre_compile.compile(pattern, flags)
  File "/Users/Raul_Costa/.pyenv/versions/3.10.13/lib/python3.10/sre_compile.py", line 788, in compile
    p = sre_parse.parse(p, flags)
  File "/Users/Raul_Costa/.pyenv/versions/3.10.13/lib/python3.10/sre_parse.py", line 955, in parse
    p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
  File "/Users/Raul_Costa/.pyenv/versions/3.10.13/lib/python3.10/sre_parse.py", line 444, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "/Users/Raul_Costa/.pyenv/versions/3.10.13/lib/python3.10/sre_parse.py", line 672, in _parse
    raise source.error("multiple repeat",
re.error: multiple repeat at position 26

Expected behavior

Pylint should run without exceptions

Pylint version

pylint==3.2.2

OS / Environment

MacOS Sonoma 14.5

Additional dependencies

No response

Activity

  1. added
    Needs triage 📥Just created, needs acknowledgment, triage, and proper labelling
    on May 30, 2024
  2. added
    Crash 💥A bug that makes pylint crash
    Needs investigation 🔬A bug or crash where it's not immediately obvious what is happenning
    and removed
    Needs triage 📥Just created, needs acknowledgment, triage, and proper labelling
    on May 30, 2024
  3. Pierre-Sassoulas commented on May 30, 2024

    @Pierre-Sassoulas
    Member

    Thank you for opening the issue. This check created so much crashes since its creation. I would never have anticipated the crazy code constructs that can ends up in an enumerate when reviewing it.

  4. added
    Needs PRThis issue is accepted, sufficiently specified and now needs an implementation
    and removed
    Needs investigation 🔬A bug or crash where it's not immediately obvious what is happenning
    on May 30, 2024
  5. mbyrnepr2 commented on May 30, 2024

    @mbyrnepr2
    Member

    Thank you. It looks like the ** in the regex in the pyproject.toml is at the heart of this. Do we need a code-change @Pierre-Sassoulas, I could be missing something?

    >>> import re
    >>> re.match('project/tooling_context/**', 'project')
    ...
    ...
    re.error: multiple repeat at position 25
  6. Pierre-Sassoulas commented on May 30, 2024

    @Pierre-Sassoulas
    Member

    Hmm, you're right, I have triaged too fast, I see an enumerate with a crash and I don't think anymore 😅

  7. mbyrnepr2 commented on May 30, 2024

    @mbyrnepr2
    Member

    Although we could handle the crash gracefully so some change is probably required :)

  8. changed the title [-]Linting of code with `itertools.repeat` raises Exception[/-] [+]Gracefully handle invalid ‘ignore-paths’ regex crash[/+] on May 31, 2024
  9. added a commit that references this issue on Jun 8, 2024
    e852a9a
  10. added this to the 3.2.4 milestone on Jun 8, 2024
  11. added a commit that references this issue on Jun 8, 2024
    3f1f7b8
  12. added a commit that references this issue on Jun 8, 2024
    37e9772
  13. added a commit that references this issue on Jun 8, 2024
    c6def6c
  14. modified the milestones: 3.2.4, 3.3.0 on Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Crash 💥A bug that makes pylint crashNeeds PRThis issue is accepted, sufficiently specified and now needs an implementation

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions