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

rxg include '\p{Han}' will throw error #7202

Closed
LonYui opened this issue Jul 19, 2022 · 5 comments · Fixed by #7228
Closed

rxg include '\p{Han}' will throw error #7202

LonYui opened this issue Jul 19, 2022 · 5 comments · Fixed by #7228
Labels
Crash 💥 A bug that makes pylint crash Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Milestone

Comments

@LonYui
Copy link

LonYui commented Jul 19, 2022

Bug description

config rxg in pylintrc with \p{Han} will throw err

Configuration

.pylintrc:

function-rgx=[\p{Han}a-z_][\p{Han}a-z0-9_]{2,30}$

Command used

pylint

Pylint output

(venvtest) tsung-hande-MacBook-Pro:robot_is_comming tsung-han$ pylint
Traceback (most recent call last):
  File "/Users/tsung-han/PycharmProjects/robot_is_comming/venvtest/bin/pylint", line 8, in <module>
    sys.exit(run_pylint())
  File "/Users/tsung-han/PycharmProjects/robot_is_comming/venvtest/lib/python3.9/site-packages/pylint/__init__.py", line 25, in run_pylint
    PylintRun(argv or sys.argv[1:])
  File "/Users/tsung-han/PycharmProjects/robot_is_comming/venvtest/lib/python3.9/site-packages/pylint/lint/run.py", line 161, in __init__
    args = _config_initialization(
  File "/Users/tsung-han/PycharmProjects/robot_is_comming/venvtest/lib/python3.9/site-packages/pylint/config/config_initialization.py", line 57, in _config_initialization
    linter._parse_configuration_file(config_args)
  File "/Users/tsung-han/PycharmProjects/robot_is_comming/venvtest/lib/python3.9/site-packages/pylint/config/arguments_manager.py", line 244, in _parse_configuration_file
    self.config, parsed_args = self._arg_parser.parse_known_args(
  File "/usr/local/Cellar/[email protected]/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/argparse.py", line 1858, in parse_known_args
    namespace, args = self._parse_known_args(args, namespace)
  File "/usr/local/Cellar/[email protected]/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/argparse.py", line 2067, in _parse_known_args
    start_index = consume_optional(start_index)
  File "/usr/local/Cellar/[email protected]/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/argparse.py", line 2007, in consume_optional
    take_action(action, args, option_string)
  File "/usr/local/Cellar/[email protected]/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/argparse.py", line 1919, in take_action
    argument_values = self._get_values(action, argument_strings)
  File "/usr/local/Cellar/[email protected]/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/argparse.py", line 2450, in _get_values
    value = self._get_value(action, arg_string)
  File "/usr/local/Cellar/[email protected]/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/argparse.py", line 2483, in _get_value
    result = type_func(arg_string)
  File "/usr/local/Cellar/[email protected]/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/re.py", line 252, in compile
    return _compile(pattern, flags)
  File "/usr/local/Cellar/[email protected]/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/re.py", line 304, in _compile
    p = sre_compile.compile(pattern, flags)
  File "/usr/local/Cellar/[email protected]/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/sre_compile.py", line 788, in compile
    p = sre_parse.parse(p, flags)
  File "/usr/local/Cellar/[email protected]/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/sre_parse.py", line 955, in parse
    p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
  File "/usr/local/Cellar/[email protected]/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/sre_parse.py", line 444, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "/usr/local/Cellar/[email protected]/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/sre_parse.py", line 555, in _parse
    code1 = _class_escape(source, this)
  File "/usr/local/Cellar/[email protected]/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/sre_parse.py", line 350, in _class_escape
    raise source.error('bad escape %s' % escape, len(escape))
re.error: bad escape \p at position 1

Expected behavior

not throw error

Pylint version

pylint 2.14.4
astroid 2.11.7
Python 3.9.13 (main, May 24 2022, 21:28:44) 
[Clang 13.0.0 (clang-1300.0.29.30)]

OS / Environment

macOS 11.6.7

@LonYui LonYui added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Jul 19, 2022
@Pierre-Sassoulas Pierre-Sassoulas added Needs reproduction 🔍 Need a way to reproduce it locally on a maintainer's machine and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Jul 19, 2022
@DanielNoord
Copy link
Collaborator

This doesn't seem like it is a pylint issue?

re.compile("[\p{Han}a-z_]") also raises normally. \p also isn't documented: https://docs.python.org/3/howto/regex.html
Is this a supported character?

@Pierre-Sassoulas Pierre-Sassoulas added Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning Waiting on author Indicate that maintainers are waiting for a message of the author and removed Needs reproduction 🔍 Need a way to reproduce it locally on a maintainer's machine labels Jul 19, 2022
@mbyrnepr2
Copy link
Member

I think this could be improved! Similar to the helpful output when passing an unrecognized option to Pylint, we could give a friendly output indicating that the regex pattern is invalid without the traceback; happy to put a MR together if you agree.

@Pierre-Sassoulas Pierre-Sassoulas added the Crash 💥 A bug that makes pylint crash label Jul 22, 2022
@Pierre-Sassoulas
Copy link
Member

Thanks @mbyrnepr2 I did not even realize it was a crash that we had to fix before your comment.

@Pierre-Sassoulas Pierre-Sassoulas added Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Waiting on author Indicate that maintainers are waiting for a message of the author labels Jul 22, 2022
@DanielNoord
Copy link
Collaborator

@mbyrnepr2 I think in the above stacktrace on line 1858 makes the most sense.

We need to decide though if we continue to run the program. I think it makes sense to still quit. If we catch regex errors there and pass we will also "allow" ignore path regexes that don't work. I don't think we should do that.

Imo, incorrect regexes are a little different from other "incorrect" options, since there is little risk that they are valid on other interpreters or versions such as old messages etc. Therefore, I'd prefer to (cleanly) exit.

@mbyrnepr2
Copy link
Member

Indeed @DanielNoord I think we are on the same page regarding this point; I would also exit instead of passing if the regex is invalid. That line you mention, we can basically try/except on re.error and exit printing the details of the pattern which is invalid.

mbyrnepr2 added a commit to mbyrnepr2/pylint that referenced this issue Jul 25, 2022
mbyrnepr2 added a commit to mbyrnepr2/pylint that referenced this issue Jul 25, 2022
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.15.0 milestone Jul 25, 2022
mbyrnepr2 added a commit to mbyrnepr2/pylint that referenced this issue Jul 25, 2022
Pierre-Sassoulas pushed a commit to mbyrnepr2/pylint that referenced this issue Jul 31, 2022
Pierre-Sassoulas added a commit that referenced this issue Jul 31, 2022
Closes #7202

* Apply the regex validation to comma-separated regular expression option values.

Co-authored-by: Pierre Sassoulas <[email protected]>
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 investigation 🔬 A bug or crash where it's not immediately obvious what is happenning 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.

4 participants