Repository navigation
[pylint] Add a configurable allowlist for magic-value-comparison (PLR2004) - #18961
Conversation
9ec2b5a to
3664fae
Compare
|
|
@DaniBodor any chance you could look at the failing tests so that we could move this PR across the line? |
|
Yes.. I'm sorry, I haven't had much time recently. Will pick it up within the next couple of weeks. |
|
Is there any update on this? π |
|
Hi. I'm sorry for the radio silence. I now have some limited availability again, so can start picking this up again, but am hesitant to bite off more than I can chew atm, so I may need some help moving this forward. |
2c8bf02 to
d8d9d7a
Compare
|
Apologies again for leaving this open for so long. |
|
No problem at all! Thanks for rebasing and for your continued work on this. Will you re-request my review when you're ready? Micha is out on vacation, but I'm happy to review :) |
|
I think something may have gone slightly awry with a merge or rebase. I'm seeing some modified ty files, which also prompted the code owner review requests. Let me know if you need any help sorting that out! |
Help would be appreciated. |
|
Huh, that's strange. It doesn't look like a merge issue to me. Are you running the tests inside of a virtual environment by any chance? Maybe even a conda environment? I wonder if that is leaking into the tests. I'm mostly guessing since it looks like additional LSP diagnostics are showing up offering to add imports like I can certainly update the snapshots on my computer to pass CI, but I expect you'll run into the same problem on future iterations, so it may be worth tracking down. |
36ea89a to
80dd15b
Compare
Yup, that was the issue. When leaving the conda env the tests passed fine without updating ty snapshots. |
|
Getting back to the content of this PR: I've addressed all the issues raised in the previous review. I've also added 2 additional features to this setting, that were not part of the original PR. |
80dd15b to
072f99b
Compare
8e6b935 to
67983b3
Compare
Typing conformance resultsNo changes detected βCurrent numbersThe percentage of diagnostics emitted that were expected errors held steady at 96.96%. The percentage of expected errors that received a diagnostic held steady at 92.96%. The number of fully passing files held steady at 106/133. |
Memory usage reportMemory usage unchanged β |
|
Hi @ntBre , I agree that cross-checking ints against floats and vice versa probably adds excessive complexity for how useful it is. In fact, I could even imagine cases where a user does want to white-list the one but not the other. So indeed probably best to remove it. I reverted the the code that does the cross-checking in the last few commits. When pushing the newest changes, I keep running into failed CI checks for which I can't figure out what is wrong. Locally, when I run any of the diagnostics listed in the dev documentation it passes just fine. |
|
Thanks for the update! The CI failure I'm seeing is for The contributing docs you linked to are for ty. This is probably the better reference for Ruff, including the mention of |
588afd4 to
7c2ac96
Compare
Thanks for pointing me to the correct contribution guidelines, not sure how I ended up on the ty guide, it's been the one I was using from the start, which explains why similar things happened a few time π€¦. I now dumped the |
|
There was a comment on the original issue regarding the name of these rules that hasn't been addressed in this PR or the discussion yet. #10009 (comment) says:
I agree that using EDIT: |
|
@ntBre , just checking in as it's been 2 months since the last updates to this PR and I'm waiting for a review. I have the feeling this PR is close to complete, but new conflicts keep popping up so it would be nice to try and finalize it :) |
ntBre
left a comment
There was a problem hiding this comment.
Thank you, and sorry for the delay! This looks good to me. I pushed one commit adding a few tests and making a couple of minor simplifications.
pylint] Add a configurable allowlist for magic-value-comparison (PLR2004)
This PR contains the following updates: | Package | Type | Update | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---|---|---| | [DavidAnson/markdownlint-cli2](https://github.com/DavidAnson/markdownlint-cli2) | repository | minor | `v0.23.3` β `v0.24.0` |  |  | | [ruff](https://docs.astral.sh/ruff) ([source](https://github.com/astral-sh/ruff), [changelog](https://github.com/astral-sh/ruff/blob/main/CHANGELOG.md)) | dependency-groups | patch | `==0.17.1` β `==0.17.3` |  |  | Note: The `pre-commit` manager in Renovate is not supported by the `pre-commit` maintainers or community. Please do not report any problems there, instead [create a Discussion in the Renovate repository](https://github.com/renovatebot/renovate/discussions/new) if you have any questions. --- ### Release Notes <details> <summary>DavidAnson/markdownlint-cli2</summary> ### [`v0.24.0`](DavidAnson/markdownlint-cli2@v0.23.3...v0.24.0) [Compare Source](DavidAnson/markdownlint-cli2@v0.23.3...v0.24.0) </details> <details> <summary>astral-sh/ruff (ruff)</summary> ### [`v0.17.3`](https://github.com/astral-sh/ruff/blob/HEAD/CHANGELOG.md#0173) [Compare Source](astral-sh/ruff@0.17.2...0.17.3) Released on 2026-10-26. ##### Preview features - \[`suspicious`] Add `shared-clock-mock` ([#​29074](astral-sh/ruff#29074)) ##### Bug fixes - \[`pyupgrade`] Avoid incorrect conversions to f-strings (`UP032`) ([#​25485](astral-sh/ruff#25485)) ##### Performance - Buffer stdout in `ruff format` ([#​29631](astral-sh/ruff#29631)) - Specialize ASCII identifier lexing ([#​29503](astral-sh/ruff#29503)) - Speed up identifier and keyword lexing ([#​29463](astral-sh/ruff#29463)) ##### Documentation - \[`flake8-bandit`] Describe what the rule actually checks for `httpx` (`S113`) ([#​27936](astral-sh/ruff#27936)) ##### Contributors - [@​itsvedantkumar](https://github.com/itsvedantkumar) - [@​charliermarsh](https://github.com/charliermarsh) - [@​anishgirianish](https://github.com/anishgirianish) ### [`v0.17.2`](https://github.com/astral-sh/ruff/blob/HEAD/CHANGELOG.md#0172) [Compare Source](astral-sh/ruff@0.17.1...0.17.2) Released on 2026-10-22. ##### Preview features - \[`complexity`] Add `unnecessary-regular-expression-compile` ([#​25533](astral-sh/ruff#25533)) ##### Bug fixes - Avoid syntax errors for type variables with starred constraints (`UP040`, `UP046`, `UP047`, `RUF053`) ([#​28362](astral-sh/ruff#28362)) - \[`pydocstyle`] Treat backslash-escaped `*args` and `**kwargs` as documented (`D417`) ([#​29536](astral-sh/ruff#29536)) - \[`pylint`] Avoid false positive on starred elements (`PLE0643`) ([#​29483](astral-sh/ruff#29483)) - \[`pylint`] Mark fixes unsafe when deleting comments (`PLR5501`, `PLW0120`) ([#​29414](astral-sh/ruff#29414)) - \[`pyupgrade`] Mark fix unsafe when deleting comments (`UP035`) ([#​29413](astral-sh/ruff#29413)) ##### Performance - Avoid intermediate names in lint name resolution ([#​29506](astral-sh/ruff#29506)) - Prefilter bidirectional Unicode checks by UTF-8 leading bytes ([#​29561](astral-sh/ruff#29561)) - Share postfix parsing and reduce expression copies ([#​29480](astral-sh/ruff#29480)) ##### Configuration - \[`pylint`] Add a configurable allowlist for `magic-value-comparison` (`PLR2004`) ([#​18961](astral-sh/ruff#18961)) ##### Documentation - Clarify documentation and correct stale guidance ([#​29374](astral-sh/ruff#29374)) - \[`pyupgrade`] Remove mentions of variance related to fix safety (`UP040`, `UP047`) ([#​29592](astral-sh/ruff#29592)) ##### Contributors - [@​fixfon](https://github.com/fixfon) - [@​MichaReiser](https://github.com/MichaReiser) - [@​zaniebot](https://github.com/zaniebot) - [@​FrancescoPezzella](https://github.com/FrancescoPezzella) - [@​anishgirianish](https://github.com/anishgirianish) - [@​rajveer3x](https://github.com/rajveer3x) - [@​charliermarsh](https://github.com/charliermarsh) - [@​LckyLike](https://github.com/LckyLke) - [@​DaniBodor](https://github.com/DaniBodor) </details> --- ### Configuration π **Schedule**: (in timezone America/Denver) - Branch creation - Between 02:00 AM and 06:59 AM, only on Tuesday (`* 2-6 * * 2`) - Automerge - At any time (no schedule defined) π¦ **Automerge**: Disabled by config. Please merge this manually once you are satisfied. β» **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. π» **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://github.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xNDguMyIsInVwZGF0ZWRJblZlciI6IjQ0LjE0OC4zIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJyZW5vdmF0ZSJdfQ==--> Reviewed-on: https://git.lichtenwalter.site/rlichten/dir2text/pulls/100
Summary
This PR allows users to specify a custom set of whitelisted values for magic value comparisons in PLR2004. The setting is named
pylint.allow_magic_values, which is consistent with a similar settingpylint.allow_magic_value_typesThe previous hard-coded allow-list was moved to the default for
pylint.allow_magic_values, giving users full control over what is and what is not a whitelisted value. This setting is added in addition to thepylint.allow_magic_value_typesand does not replace it. Any value that is whitelisted due to either of these settings is not considered a linting violation.Note that as far as I could tell, no other setting allows floats or complex numbers as inputs, so I created a few helper methods to deal with these properly (mainly relating to floating point variation).
Test Plan
I have tested the settings with a number of cases manually in a repository I work on regularly. I have not added any extensive (combinatorial) tests to the test suite.
Note
I don't know whether you have any policy on using or disclosing the use of code generators, but I definitely relied heavily on this to solve some of the issues I ran into during development. Ultimately, all code was reviewed by me before pushing.
fix: #10009