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

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

Closed
RaulWCosta opened this issue May 30, 2024 · 4 comments · Fixed by #9712
Closed

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

RaulWCosta opened this issue May 30, 2024 · 4 comments · Fixed by #9712
Labels
Crash 💥 A bug that makes pylint crash Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Milestone

Comments

@RaulWCosta
Copy link

RaulWCosta commented May 30, 2024

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

@RaulWCosta RaulWCosta added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label May 30, 2024
@Pierre-Sassoulas Pierre-Sassoulas 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 labels May 30, 2024
@Pierre-Sassoulas
Copy link
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.

@Pierre-Sassoulas Pierre-Sassoulas added Needs PR This 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 labels May 30, 2024
@mbyrnepr2
Copy link
Member

mbyrnepr2 commented May 30, 2024

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

@Pierre-Sassoulas
Copy link
Member

Pierre-Sassoulas commented May 30, 2024

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

@mbyrnepr2
Copy link
Member

mbyrnepr2 commented May 30, 2024

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

@mbyrnepr2 mbyrnepr2 changed the title Linting of code with itertools.repeat raises Exception Gracefully handle invalid ‘ignore-paths’ regex crash May 31, 2024
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Jun 8, 2024
Fix 'ignore-paths', in particular, but others using this function too.

Closes pylint-dev#9680
@Pierre-Sassoulas Pierre-Sassoulas added this to the 3.2.4 milestone Jun 8, 2024
Pierre-Sassoulas added a commit that referenced this issue Jun 8, 2024
Fix 'ignore-paths', in particular, but others using this function too.

Closes #9680
github-actions bot pushed a commit that referenced this issue Jun 8, 2024
Fix 'ignore-paths', in particular, but others using this function too.

Closes #9680

(cherry picked from commit 3f1f7b8)
Pierre-Sassoulas added a commit that referenced this issue Jun 8, 2024
Fix 'ignore-paths', in particular, but others using this function too.

Closes #9680

(cherry picked from commit 3f1f7b8)
@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 3.2.4, 3.3.0 Jun 12, 2024
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