-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Experimental: Unify NamingSchemes. #3704
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
Conversation
b231639
to
fa1f686
Compare
I don't understand these test failures. I'm unable to reproduce them reliably, and I notice they only happen when I run the whole test suite -- the tests alone don't fail. I also see that I sometimes get the same errors in master branch. Are there currently flaky tests in master? |
632dcc0
to
5b8f498
Compare
The current default pylint naming schemes only differ on three parameters: 1. characters allowed at beginning of name 2. characters allowed elsewhere 3. minimum length of name Where this was not true was due to either bugs, oversight, or legacy inertia. It's hard for me to tell the difference. Many odd discrepancies among the naming schemes have been rectified, and this change will bother users by calling out some of their bizarre naming conventions, but all such issues are valid. For churn considerations, I've not (yet?) modified the names of the naming scheme objects although they've transitioned from being classes to objects, and there's a couple other bits of odd naming in here for the same reason. My aim was chiefly to show that this was possible, and spur consideration of the idea. A further improvement would be to set a "minimum length" for names in the configuration, which should be checked apart from "naming scheme" issues. This would greatly reduce the need for users to read and understand regular expressions, and will make messages more actionable, but also separating that additional resonsibility would further simplify and rectify the naming schemes.
5b8f498
to
edae48b
Compare
1 similar comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bukzor thanks a lot for this PR and sorry for the delay.
It is clearly an improvement in our naming scheme management.
However i'm a bit confused by the fact that, at this point, this PR prevents the user to use variable with only one character in its name...
By the way, i would like to have @PCManticore on this topic.
|
||
1. increase the length of names to be more descriptive (recommended) | ||
2. add strange-but-useful names to the good-names configuration | ||
3. override the default regexen, via pylintrc (not recommended) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is that not recommended?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not recommended because even for those deeply familiar with regex (few) it is much too easy to make regex with unintended matches / exclusions.
name_template = r"[^\W\d_%s][^\W%s]%s" | ||
|
||
def __init__(self, head_exclude: str, tail_exclude: str, min_length: int): | ||
self.head_exclude = head_exclude |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO it could be interesting to add comments explaining what do you call head and tail. From what i understand, head is only one character long whereas tail is all the rest. I'm i right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, exactly. As in head and tail of a snake -- the tail is everything but the head.
@@ -1,4 +1,4 @@ | |||
# pylint: disable=literal-comparison,missing-docstring,misplaced-comparison-constant | |||
# pylint: disable=literal-comparison,missing-docstring,misplaced-comparison-constant,invalid-name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find a little bit damageable if pylint
is not compatible with constant name that are one letter long.
What do you think about it?
==input.func_w0801:3 | ||
==input.w0801_same:3 | ||
==input.func_w0801:4 | ||
==input.w0801_same:4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this change needed?
@@ -0,0 +1,2 @@ | |||
[basics] | |||
good-names=i,j,k,ex,Run,_,_dt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once again i think it is very risky to forbid using single character named variable...
@bukzor Thanks for you initial contribution. I would like to add this to |
I'm going to close this PR as it has become stale. I looked at the changes this PR would introduce and have decided not to take them further myself. I think a real contribution would be finding a way to do the naming styles without having to compile 25+ regex patterns, but I'm not sure if that is even feasible. |
I intend to revive this work -- after a long haitus, I'm once again participaing in the open-source community. Please advise:
|
Welcome back! 😄
I think a fresh one is probably better since many of the files here have now moved or significantly changed. That said, I know there was some discussion about whether we should pursue the changes in this PR. I'm still sympathetic to simplifying this code, but I'm not sure how feasible the current approach still is. |
Thank you!
Roger.
I'm aware that the approach taken isn't strictly agreeable, but I do believe the goals are still relevant and attainable. Once I have something worth discussing I'll bother you again. Async text (i.e. github issues) isn't very conducive to debating abstract ideas such as hypothetical implementations, especially between strangers. How do you normally handle such complex communications? |
Normally we use issues to discuss significant proposals of change. It's not really perfect like you said, but it also helps narrow the scope of PRs which greatly helps with reviewing them. If the discussion in a PR is becoming too long it is often a good indication that it might try to do too much in one PR. |
Hello @bukzor and welcome back ! (I started to work on this issue myself and lost the code some time ago so I had some ideas about it) I think short variable name should be correctly checked as per hippo's comment. Also imo a split between a new check for variable names that are too small and variable names not respecting the name convention is required (using old_names so retro compatibility for all messages disabled with 'invalid-name' previousely are still disabled for both new message). We usually use async text communication for everything as we're in various timezones and pylint is something I do on my free time / when convenient. So I don't want to schedule a call unless absolutely necessary. But I think it's possible to talk about the required steps and do them one by one with issues as Daniel said though. |
Thank you :D
Please expand on "correctly" here? My best guess is that you mean: One-character variables should be admitted by the name checker without error, by default.
To clarify, you're advocating a split of the existing If so, my goal would be to add the two new checkers in a disabled-by-default state until you're ready, while leaving the old checker untouched, for now.
I don't understand this bit. What is
Got it! I will endevour to adopt this workflow. Thank you for including me :) |
I was thinking that a name that is in the list of accepted name should be ok for both checks.
I realize that if we keep regex this is going to be hell so maybe no invalid name for name that are too short when the regex used is the default one (maybe someone crafted a masterful regex that handle short names properly somewhere) is acceptable:
I think depending on what we decide for the problem above having one checker instead of two could be simpler but yes.
That could work well but add complexity, if we can refactor the existing checker it's probably less work overall. How would you do the change to the TypeVar check @DanielNoord ? Would a standalone checker with only TypeVar work ? Should we keep TypeVar "generic" ?
Yes, check this code: https://github.com/PyCQA/pylint/blob/main/pylint/checkers/base/docstring_checker.py#L64 |
this supercedes pylint-dev#3704
Description
The current default pylint naming schemes only differ on three parameters:
Where this was not true was due to either bugs, oversight, or legacy
inertia; i's hard for me to tell the difference. Many odd
discrepancies among the naming schemes have been rectified, and this
change will bother users by calling out some of their bizarre naming
conventions, but all such issues are valid.
For churn considerations, I've not (yet?) modified the names of the
naming scheme objects although they've transitioned from being classes
to objects, and there's a couple other bits of odd naming in here for
the same reason. My aim was chiefly to show that this was possible, and
spur consideration of the idea.
A further improvement would be to set a "minimum length" for names in
the configuration, which should be checked apart from "naming scheme"
issues. This would greatly reduce the need for users to read and
understand regular expressions, and will make messages more actionable,
but also separating that additional resonsibility would further simplify
and rectify the naming schemes.
Type of Changes