-
-
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
enable/disable options in rcfile should not depend on the order with which they are specified #3696
Comments
+1 from my side. Same goes for the pyproject.toml file |
This should be done during a configuration refactor, or it will be a small patch on something old and already very patched using optparse. |
I tried to figure out where exactly this order sensitive disable/enable comes from since it affects CLI, init and toml config. Can you point me to the right place? I can try to open a PR |
Everything happens in |
Thanks for the hint. As far as I can say, the behavior comes from this code:
|
I can't think of a solution that will keep this for loop in its current state either. |
Are there any plans to refactor the configuration module to use argparse and to modernize it a little bit?
But the other way round, we also miss scenarios:
So both orders have up and downsides. A possible statement could be: "It's not a bug, it's a feature 😄 " Else maybe something like this (quite hacky and we need to decide on an order [...]
order_sensitive_config = {}
if option in ["enable", "disable"]:
order_sensitive_config[option] = value
continue
try:
self.global_set_option(option, value)
except (KeyError, optparse.OptionError):
continue
[...]
if "enable" in order_sensitive_config:
self.global_set_option("enable", order_sensitive_config["enable"])
if "disable" in order_sensitive_config:
self.global_set_option("disable", order_sensitive_config["disable"]) |
I think the logical order is to always take
My reasoning is that you would not specify disable or enable when you use You're right that it can be considered a breaking change, maybe we could move that to 3.0, or simply call that a bug fix, it depends on how "intuitive" this solution really is (maybe I've convinced myself but it will not be understood this way at all ?). Let me know what you think.
There are plans (https://github.com/PyCQA/pylint/projects/1) but this is not a priority for most contributors and as a maintainers most of our time consists of reviewing merge requests, triaging issues and implementing absolutely necessary changes like the new match pattern in python 3.10, so there's very little time for this kind of (very important) refactoring project. |
Thanks a lot for this insights. I agree, it depends a lot how you look on this: It's either a breaking change or a bug fix. Since you asked what I would do: Personally, I would not use "dynamic" loops at all, but handle the options one by one. This leads obviously to more code, but options order dependencies and so in will disappear. But this is not possible w/o a refactoring. So, what do you think about my approach above? It's not very nice, but I have o other idea. I like the idea to handle "all" special; this can be easily added. |
Thank you. There's I think foor aspects to the refactor :
If you can refactor only this for loop without modifying the other aspect that's fine for me, but a preliminary refactor might help. In particular I think argparse design force each argument to be handled separately, and this for loop would simply disappear (?) as well as a lot of optparse code that you don't need to do anymore nowadays. I don't know about click or confuse but this would be another possibility. |
To be honest, moving away from optparse to argparse/click (click is btw very nice) would be (as far as I can say) a very drastic change. I did only one small change so far in pylint, so I'm kind of afraid doing this change. As you said, there are many patches and callbacks making it hard to understand for beginners. In the end, the code is not even typed, which add just more complexity and hurdles. Any idea how we can move on from here? Maybe a complete drop of the old code with a fresh design could help? |
Yes, that would make a lot of sense especially for the transition to click or argparse. I think it's a lot easier to reproduce pylint's arg parsing from zero then replace the original code than to progressively refactor. It would be a breaking change though. I'm pretty sure that some strange bugs due to everything being done by hand with optparse are considered feature now. |
I spoke about confuse too, because it could help define a template yaml and have the argument to parse done automatically. https://confuse.readthedocs.io/en/latest/
|
I might miss a detail about confuse, but it seems not to support toml and ini out of the box, doesn't it? |
Yes, we're handling a lot of possible file and format. Maybe migrating to |
Pinging @jacobtylerwalls as I'm not sure you're subscribed to this issue and I'd like some input from you as well. I have been thinking about this some more and I wonder if we should close this as
|
I think it's valuable and probably not too hard. It's not a great solution to have to move your rcfile choices around. Proposal:
All it "breaks" is the person who has |
That would require pre-scanning all providers for the |
An example of how the current behavior can be misleading is what happened in #8328 when we tried to document |
Hello,
i'm running
pylint 2.5.3 / astroid 2.4.2
; i kinda understand why$ pylint --enable=all --disable=fixme
behaves differently than
$ pylint --disable=fixme --enable=all
(where the first command enables everything and then disable
fixme
, while the second command the disable option is overwritten byenable=all
) but i dont think it should be the same in the rcfile: thedisable
section is (by default) before theenable
section, so if i want to have the same effect of command1 i need to swap the sections around.on the cli i can specify multiple enable/disable options, but that's not allowed in the rcfile, so the
current result is extremely counter-intuitive; and rcfile with
is clear what result the user wants: to enable all checks except for some, and i shouldnt need to move config options around.
can you please get that fixed?
Thanks!
The text was updated successfully, but these errors were encountered: