-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
bad-names-rgxs mangles regular expressions with commas #7229
Comments
The crash will be fixed in #7228. Regarding the issue with the comma, I think a list of regex is not possible and it could be a big regex with both smaller regex and a |
thanks for the response! As you mentioned, this isn't urgent or blocking, since quantifiers are the only python regex syntax that uses commas and commas aren't otherwise valid in python identifiers. Any quantifier can be reworded with some copy/pasting and |
At the least, I think this might warrant some explicit documentation since this could silently create two valid regexes instead of just erroring out, which is the worst scenario IMO |
I'm not suggesting you should work around this using |
Hey @Pierre-Sassoulas. The crash in this case won't be fixed by #7228 since this has a different argument type. Would you prefer if I update the existing MR to handle this case also or create a separate MR? Although - depending on if you want to keep the csv functionality, perhaps we can treat both cases like we are passing one single regex (and not a comma-sepatated list of them) |
What do you think @DanielNoord , should we keep the sequence of pattern type and fix it ? |
Changing that would be a major break for many options. I do think we should try and avoid them in the future. |
But its ok to validate each individual regex in the csv using the new function here, right @DanielNoord? |
Yeah! Let's exit cleanly. |
If we keep this, should we do something more complex like not splitting on a comma if it's inside an unclosed |
I think it makes sense to remove it in Pylint 3.0 if 1. we want to remove it & 2. the concern for removing it is that it is a breaking change. |
Updated #7228 to handle the crash in this issue; although nothing is in place to avoid splitting in the middle of the regex itself. |
I can make a PR to avoid splitting on commas in quantifiers without breaking existing functionality, if you'd like. Since commas in regular expressions only occur in narrow circumstances, this is feasible without too much complexity, IMO |
We appreciate all the help we can get :) How would you do it @lbenezriravin ? What do you think of "not splitting on a comma if it's inside an unclosed |
Wouldn't it be a better use of our efforts to deprecate these options and create new ones which don't split? |
@Pierre-Sassoulas yeah, that's exactly what I was thinking. Here's a quick prototype that I verified works on the trivial cases. Obviously I'd clean it up before PRing
@DanielNoord I agree that deprecating the functionality in the long term is best, but if I can quickly patch a bug in the short term, I'm happy to help. |
I'm hesitating between 'let's do the fix and wait to see if the fix is good enough before deprecation' and 'let's warn of the deprecation only when there's comma inside {} thanks to the fix' 😄 |
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.
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.
Bug description
Since pylint splits on commas in this option, instead of taking a list of strings, if there are any commas in the regular expression, the result is mangled before being parsed. The config below demonstrates this clearly by causing pylint to crash immediately.
Configuration
Command used
Pylint output
Expected behavior
I would expect any valid regular expression to be expressible in this option. If not directly, adding some way to escape commas so that this issue can be worked around.
Pylint version
OS / Environment
Pop! OS 22.04
Additional dependencies
No response
The text was updated successfully, but these errors were encountered: