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

Ignore quantifiers when splitting comma-separated regexes #7241

Closed
wants to merge 4 commits into from

Conversation

lbenezriravin
Copy link
Contributor

@lbenezriravin lbenezriravin commented Jul 28, 2022

Type of Changes

Type
βœ“ πŸ› Bug fix

Description

When parsing comma-separated lists of regular expressions in the config, ignore
commas that are inside braces since those indicate quantifiers, not delineation
between expressions.

There may be conflicts with #7228, lmk if you'd prefer if this gets merged first or second.

Closes #7229

lihu added 3 commits July 28, 2022 18:28
Do not split on commas if they are between braces, since that indicates
a quantifier. Also added a protection for slow implementations since
existing workarounds may result in long strings of chained regular
expressions.
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good already, thank you ! I'll put the "need a decision" label so we don't merge it before we decide what we do in 3.0.

tests/config/test_config.py Outdated Show resolved Hide resolved
regexps: deque[deque[str] | None] = deque([None])
open_braces = False
for char in value:
if char == "{":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on the result of the discussion we should warn the user of deprecation here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't it be on line 346? That's where we split regular expressions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, my bad.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know a year ago we were floating the idea of deprecations, but we're not ready to commit to a new plan IMO.

@Pierre-Sassoulas Pierre-Sassoulas added the Needs decision πŸ”’ Needs a decision before implemention or rejection label Jul 29, 2022
@coveralls
Copy link

coveralls commented Jul 29, 2022

Pull Request Test Coverage Report for Build 2762066289

  • 19 of 20 (95.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.0008%) to 95.249%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pylint/utils/utils.py 18 19 94.74%
Totals Coverage Status
Change from base Build 2737748168: -0.0008%
Covered Lines: 16839
Relevant Lines: 17679

πŸ’› - Coveralls

Overkill, slows down unit tests

Co-authored-by: Pierre Sassoulas <[email protected]>
@github-actions
Copy link
Contributor

πŸ€– According to the primer, this change has no effect on the checked open source code. πŸ€–πŸŽ‰

This comment was generated for commit b48c339

@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 2.15.0, 2.16.0 Aug 23, 2022
@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 2.16.0, 2.17.0 Jan 8, 2023
@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 2.17.0, 3.0.0 Mar 7, 2023
@jacobtylerwalls jacobtylerwalls added Needs review πŸ” Needs to be reviewed by one or multiple more persons and removed Needs decision πŸ”’ Needs a decision before implemention or rejection labels Jul 2, 2023
@jacobtylerwalls jacobtylerwalls modified the milestones: 3.0.0, 3.0.0a7 Jul 2, 2023
@jacobtylerwalls jacobtylerwalls self-requested a review July 2, 2023 20:21
Copy link
Member

@jacobtylerwalls jacobtylerwalls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I left cosmetic feedback only. Thanks for adding a regression test that fails on main.

I think we should merge. We should not let there be silent parsing failures when trying to use regular expressions. (What a gotcha!)

@@ -0,0 +1,5 @@
When parsing comma-separated lists of regular expressions in the config, ignore
commas that are inside braces since those indicate quantiers, not dilineation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
commas that are inside braces since those indicate quantiers, not dilineation
commas that are inside braces since those indicate quantifiers, not delineation

@@ -5,6 +5,8 @@
from __future__ import annotations

import os
import re
import timeit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import timeit

assert _template_run(in_string) == [re.compile(regex) for regex in expected]



Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

@jacobtylerwalls jacobtylerwalls removed the Needs review πŸ” Needs to be reviewed by one or multiple more persons label Jul 2, 2023
@jacobtylerwalls jacobtylerwalls modified the milestones: 3.0.0a7, 2.17.5 Jul 3, 2023
@jacobtylerwalls
Copy link
Member

@lbenezriravin If you enable maintainers to push to this fork I can resolve the merge conflicts for you and add the cosmetic changes.

@@ -34,6 +35,7 @@
"HAS_ISORT_5",
"IsortDriver",
"_check_csv",
"_check_regexp_csv",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is private, this should not be in __all__.

Suggested change
"_check_regexp_csv",

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR currently uses it on the module, so it has to stay, unless we refactor. It was a reasonable choice for the PR author to adhere to the existing muddled pattern. I'm inclined to merge as is.

@Pierre-Sassoulas Pierre-Sassoulas added the Waiting on author Indicate that maintainers are waiting for a message of the author label Jul 11, 2023
@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 2.17.5, 2.17.6 Jul 26, 2023
@jacobtylerwalls
Copy link
Member

Will merge in #8898. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backported Bug πŸͺ² Configuration Related to configuration Waiting on author Indicate that maintainers are waiting for a message of the author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bad-names-rgxs mangles regular expressions with commas
5 participants