-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
PLC0206 diagnostic location is confusing #14900
Comments
Thanks for submitting this! So I think that the error message is pointing to the wrong spot (which is confusing...), PLC0206 is complaning about this: if norm_name in updated_packages:
version = packages[package] So I think it would be compatible with both rules to do something more like: diff --git a/tmp.py b/tmp2.py
index dfa6d6f..6975214 100644
--- a/tmp.py
+++ b/tmp2.py
@@ -1,9 +1,8 @@
outdated = []
skipped = []
-for package in packages.keys():
+for package, version in packages.items():
norm_name = pep423_name(package)
if norm_name in updated_packages:
- version = packages[package]
if isinstance(version, Mapping):
version = parse_version(version.get("version", "").replace("==", ""))
else: But I can't quite tell from your code if you're trying to mutate the dictionary key at that point, in which case you'd have to do something else. (The above patch would also violate redefined-loop-name (PLW2901), so if that rule is also enabled you would have to name the loop variable something else). |
I do think the error message being in the wrong spot is a bug though - we should fix that |
I started looking into this and there's a bit of a design question: how should we handle multiple uses of the dictionary value inside the for-loop? Some options:
@AlexWaygood / @MichaReiser have y'all run into this issue before where you want to display multiple text ranges for a single diagnostic? Is there prior art? |
Changing the location is, unfortunately, a breaking change because it breaks all To me it's not clear what the right location should be but I'm leaning towards:
However, I can see how this isn't useful. That's why I'm leaning towards renaming and redefining the rule to flag the usages instead. Requiring multiple |
First it tells me no to use:
When I try
dict.keys
it still complains.When I try `dict.item() and throw away value, it still complains:
I believe PLC0206 should not be raised if I use
dict.keys()
The text was updated successfully, but these errors were encountered: