-
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
[pylint
] C1901: compare-to-empty-string
#3405
Conversation
if matches!(op, Cmpop::Eq | Cmpop::NotEq) { | ||
if let ExprKind::Constant { value: v, .. } = &rhs.node { | ||
let k = unparse_constant(v, checker.stylist); | ||
if k == "\"\"" || k == "''" { |
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.
My recommendation would be to instead match
on the value
, and check for value.is_empty()
in Constant::Str(value)
. Would that have any problems? (It could also catch cases in which the string had a prefix, like u
, which this would miss.)
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.
Separately: does Pylint catch x == b""
? Or x == f""
?
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 think matching on the value definitely makes sense.
I just tested the latest stable release of pylint and it does not catch the b"" or f"" cases, it only shows the lint warning for ""
without any specifiers. Pylint also shows the lint warning for x is ""
and x is not ""
which seems sensible as well.
ViolationsCmpop::Is | ViolationsCmpop::Eq => "", | ||
// the assumption is that this message will only ever be shown | ||
// if op is `in`, `=`, `not in`, `!=` | ||
_ => "not", |
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'd suggest just making a new enum
in this file specifically for this violation, to encode this assumption in the types themselves.
I've fixed the diagnostics message and tested the code and it all seems to work, unfortunately I've got a busier week than anticipated so I'll see if I can implement autofix in another PR sometime later |
No prob, thanks for this! |
pylint
] C1901: compare-to-empty-string
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [ruff](https://togithub.com/charliermarsh/ruff) | `^0.0.254` -> `^0.0.255` | [![age](https://badges.renovateapi.com/packages/pypi/ruff/0.0.255/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/ruff/0.0.255/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/ruff/0.0.255/compatibility-slim/0.0.254)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/ruff/0.0.255/confidence-slim/0.0.254)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>charliermarsh/ruff</summary> ### [`v0.0.255`](https://togithub.com/charliermarsh/ruff/releases/tag/v0.0.255) [Compare Source](https://togithub.com/charliermarsh/ruff/compare/v0.0.254...v0.0.255) <!-- Release notes generated using configuration in .github/release.yml at main --> #### What's Changed ##### Rules - \[`flake8-pie`] Fix PIE802 broken auto-fix with trailing comma by [@​JonathanPlasse](https://togithub.com/JonathanPlasse) in [https://github.com/charliermarsh/ruff/pull/3402](https://togithub.com/charliermarsh/ruff/pull/3402) - \[`flake8-pie`] Implement autofix for PIE810 by [@​kyoto7250](https://togithub.com/kyoto7250) in [https://github.com/charliermarsh/ruff/pull/3411](https://togithub.com/charliermarsh/ruff/pull/3411) - \[`flake8-bugbear`] Add `flake8-bugbear`'s B030 rule by [@​aacunningham](https://togithub.com/aacunningham) in [https://github.com/charliermarsh/ruff/pull/3400](https://togithub.com/charliermarsh/ruff/pull/3400) - \[`pycodestyle`] Add E231 by [@​carlosmiei](https://togithub.com/carlosmiei) in [https://github.com/charliermarsh/ruff/pull/3344](https://togithub.com/charliermarsh/ruff/pull/3344) - \[`pyupgrade`] Flag deprecated (but renamed) imports in UP035 by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3448](https://togithub.com/charliermarsh/ruff/pull/3448) - \[`pyupgrade`] Remap ChainMap, Counter, and OrderedDict imports to collections by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3392](https://togithub.com/charliermarsh/ruff/pull/3392) - \[`pylint`] C1901: compare-to-empty-string by [@​AreamanM](https://togithub.com/AreamanM) in [https://github.com/charliermarsh/ruff/pull/3405](https://togithub.com/charliermarsh/ruff/pull/3405) - \[`pylint`] Implement W1508 invalid-envvar-default by [@​latonis](https://togithub.com/latonis) in [https://github.com/charliermarsh/ruff/pull/3449](https://togithub.com/charliermarsh/ruff/pull/3449) - \[`pylint`] Implement E1507 invalid-envvar-value by [@​latonis](https://togithub.com/latonis) in [https://github.com/charliermarsh/ruff/pull/3467](https://togithub.com/charliermarsh/ruff/pull/3467) ##### Settings - Infer `target-version` from project metadata by [@​JonathanPlasse](https://togithub.com/JonathanPlasse) in [https://github.com/charliermarsh/ruff/pull/3470](https://togithub.com/charliermarsh/ruff/pull/3470) - Implement configuration options `runtime-evaluated-decorators` and `runtime-evaluated-base-classes` for `flake8-type-checking` by [@​sasanjac](https://togithub.com/sasanjac) in [https://github.com/charliermarsh/ruff/pull/3292](https://togithub.com/charliermarsh/ruff/pull/3292) - Add Azure DevOps as a `--format` option. by [@​StefanBRas](https://togithub.com/StefanBRas) in [https://github.com/charliermarsh/ruff/pull/3335](https://togithub.com/charliermarsh/ruff/pull/3335) ##### Bug Fixes - Re-enable the T and C linter prefix selectors by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3452](https://togithub.com/charliermarsh/ruff/pull/3452) - Treat unary operations on constants as constant-like by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3348](https://togithub.com/charliermarsh/ruff/pull/3348) - Skip byte-order-mark at start of file by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3343](https://togithub.com/charliermarsh/ruff/pull/3343) - Don't enforce typing-import rules in .pyi files by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3362](https://togithub.com/charliermarsh/ruff/pull/3362) - Include entire prefix when reporting rule selector errors by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3375](https://togithub.com/charliermarsh/ruff/pull/3375) - Handle multi-line fixes for byte-string prefixing by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3391](https://togithub.com/charliermarsh/ruff/pull/3391) - Catch RET504 usages via decorators by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3395](https://togithub.com/charliermarsh/ruff/pull/3395) - Ignore multiply-assigned variables in RET504 by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3393](https://togithub.com/charliermarsh/ruff/pull/3393) - \[FIX] PYI011: recognize `Bool` / `Float` / `Complex` numbers as simple defaults by [@​XuehaiPan](https://togithub.com/XuehaiPan) in [https://github.com/charliermarsh/ruff/pull/3459](https://togithub.com/charliermarsh/ruff/pull/3459) - Respect ignores for runtime-import-in-type-checking-block (TCH004) by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3474](https://togithub.com/charliermarsh/ruff/pull/3474) - Avoid panicking in invalid_escape_sequence by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3338](https://togithub.com/charliermarsh/ruff/pull/3338) - fix: Emit a more useful error if an `extend` points at a non-existent ruff.toml file. by [@​DanCardin](https://togithub.com/DanCardin) in [https://github.com/charliermarsh/ruff/pull/3417](https://togithub.com/charliermarsh/ruff/pull/3417) - Respect `--show-fixes` with `--fix-only` by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3426](https://togithub.com/charliermarsh/ruff/pull/3426) - When "Args" and "Parameters" are present, prefer NumPy style by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3430](https://togithub.com/charliermarsh/ruff/pull/3430) - Remove empty line after RUF100 auto-fix by [@​JonathanPlasse](https://togithub.com/JonathanPlasse) in [https://github.com/charliermarsh/ruff/pull/3414](https://togithub.com/charliermarsh/ruff/pull/3414) - Avoid removing un-aliased exceptions in `OSError`-aliased handlers by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3451](https://togithub.com/charliermarsh/ruff/pull/3451) - Use a hash to fingerprint GitLab CI output by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3456](https://togithub.com/charliermarsh/ruff/pull/3456) - Avoid respecting noqa directives when RUF100 is enabled by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3469](https://togithub.com/charliermarsh/ruff/pull/3469) - Output GitLab paths relative to `CI_PROJECT_DIR` by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3475](https://togithub.com/charliermarsh/ruff/pull/3475) - Implement an iterator for universal newlines by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3454](https://togithub.com/charliermarsh/ruff/pull/3454) #### New Contributors - [@​sasanjac](https://togithub.com/sasanjac) made their first contribution in [https://github.com/charliermarsh/ruff/pull/3292](https://togithub.com/charliermarsh/ruff/pull/3292) - [@​aacunningham](https://togithub.com/aacunningham) made their first contribution in [https://github.com/charliermarsh/ruff/pull/3380](https://togithub.com/charliermarsh/ruff/pull/3380) - [@​orf](https://togithub.com/orf) made their first contribution in [https://github.com/charliermarsh/ruff/pull/3389](https://togithub.com/charliermarsh/ruff/pull/3389) - [@​DanCardin](https://togithub.com/DanCardin) made their first contribution in [https://github.com/charliermarsh/ruff/pull/3417](https://togithub.com/charliermarsh/ruff/pull/3417) - [@​AreamanM](https://togithub.com/AreamanM) made their first contribution in [https://github.com/charliermarsh/ruff/pull/3405](https://togithub.com/charliermarsh/ruff/pull/3405) - [@​kyoto7250](https://togithub.com/kyoto7250) made their first contribution in [https://github.com/charliermarsh/ruff/pull/3411](https://togithub.com/charliermarsh/ruff/pull/3411) - [@​latonis](https://togithub.com/latonis) made their first contribution in [https://github.com/charliermarsh/ruff/pull/3449](https://togithub.com/charliermarsh/ruff/pull/3449) - [@​XuehaiPan](https://togithub.com/XuehaiPan) made their first contribution in [https://github.com/charliermarsh/ruff/pull/3459](https://togithub.com/charliermarsh/ruff/pull/3459) - [@​CalumY](https://togithub.com/CalumY) made their first contribution in [https://github.com/charliermarsh/ruff/pull/3461](https://togithub.com/charliermarsh/ruff/pull/3461) - [@​YDX-2147483647](https://togithub.com/YDX-2147483647) made their first contribution in [https://github.com/charliermarsh/ruff/pull/3473](https://togithub.com/charliermarsh/ruff/pull/3473) **Full Changelog**: astral-sh/ruff@v0.0.254...v0.0.255 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/ixm-one/pytest-cmake-presets). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4xNjAuMCIsInVwZGF0ZWRJblZlciI6IjM0LjE2MC4wIn0=--> Signed-off-by: Renovate Bot <bot@renovateapp.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [ruff](https://togithub.com/charliermarsh/ruff) | `==0.0.254` -> `==0.0.256` | [![age](https://badges.renovateapi.com/packages/pypi/ruff/0.0.256/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/ruff/0.0.256/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/ruff/0.0.256/compatibility-slim/0.0.254)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/ruff/0.0.256/confidence-slim/0.0.254)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>charliermarsh/ruff</summary> ### [`v0.0.256`](https://togithub.com/charliermarsh/ruff/releases/tag/v0.0.256) [Compare Source](https://togithub.com/charliermarsh/ruff/compare/v0.0.255...v0.0.256) <!-- Release notes generated using configuration in .github/release.yml at main --> #### What's Changed ##### Bug Fixes - PYI011: allow `math` constants in defaults by [@​XuehaiPan](https://togithub.com/XuehaiPan) in [https://github.com/charliermarsh/ruff/pull/3484](https://togithub.com/charliermarsh/ruff/pull/3484) - Remove erroneous C4-to-C40 redirect by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3488](https://togithub.com/charliermarsh/ruff/pull/3488) - fix lack of `not` in error message by [@​Czaki](https://togithub.com/Czaki) in [https://github.com/charliermarsh/ruff/pull/3497](https://togithub.com/charliermarsh/ruff/pull/3497) - Ensure that redirect warnings appear exactly once per code by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3500](https://togithub.com/charliermarsh/ruff/pull/3500) - Allow f-strings and concatenations in os.getenv by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3516](https://togithub.com/charliermarsh/ruff/pull/3516) - Allow string percent formatting in os.getenv by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3518](https://togithub.com/charliermarsh/ruff/pull/3518) - Refine complexity rules for try-except-else-finally by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3519](https://togithub.com/charliermarsh/ruff/pull/3519) - Replicate inline comments when splitting single-line imports by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3521](https://togithub.com/charliermarsh/ruff/pull/3521) - Avoid PEP 604 isinstance errors for starred tuples by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3527](https://togithub.com/charliermarsh/ruff/pull/3527) - Avoid tracking as-imports separately with force-single-line by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3530](https://togithub.com/charliermarsh/ruff/pull/3530) - Fix PYI011 and add auto-fix by [@​JonathanPlasse](https://togithub.com/JonathanPlasse) in [https://github.com/charliermarsh/ruff/pull/3492](https://togithub.com/charliermarsh/ruff/pull/3492) - Avoid PEP 604 panic with empty tuple by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3526](https://togithub.com/charliermarsh/ruff/pull/3526) - Add last remaining deprecated typing imports by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3529](https://togithub.com/charliermarsh/ruff/pull/3529) - Avoid unused argument violations in .pyi files by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3533](https://togithub.com/charliermarsh/ruff/pull/3533) ##### Other Changes - Include individual path checks in --verbose logging by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3489](https://togithub.com/charliermarsh/ruff/pull/3489) - Allow `# ruff:` prefix for isort action comments by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3493](https://togithub.com/charliermarsh/ruff/pull/3493) **Full Changelog**: astral-sh/ruff@v0.0.255...v0.0.256 ### [`v0.0.255`](https://togithub.com/charliermarsh/ruff/releases/tag/v0.0.255) [Compare Source](https://togithub.com/charliermarsh/ruff/compare/v0.0.254...v0.0.255) <!-- Release notes generated using configuration in .github/release.yml at main --> #### What's Changed ##### Rules - \[`flake8-pie`] Fix PIE802 broken auto-fix with trailing comma by [@​JonathanPlasse](https://togithub.com/JonathanPlasse) in [https://github.com/charliermarsh/ruff/pull/3402](https://togithub.com/charliermarsh/ruff/pull/3402) - \[`flake8-pie`] Implement autofix for PIE810 by [@​kyoto7250](https://togithub.com/kyoto7250) in [https://github.com/charliermarsh/ruff/pull/3411](https://togithub.com/charliermarsh/ruff/pull/3411) - \[`flake8-bugbear`] Add `flake8-bugbear`'s B030 rule by [@​aacunningham](https://togithub.com/aacunningham) in [https://github.com/charliermarsh/ruff/pull/3400](https://togithub.com/charliermarsh/ruff/pull/3400) - \[`pycodestyle`] Add E231 by [@​carlosmiei](https://togithub.com/carlosmiei) in [https://github.com/charliermarsh/ruff/pull/3344](https://togithub.com/charliermarsh/ruff/pull/3344) - \[`pyupgrade`] Flag deprecated (but renamed) imports in UP035 by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3448](https://togithub.com/charliermarsh/ruff/pull/3448) - \[`pyupgrade`] Remap ChainMap, Counter, and OrderedDict imports to collections by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3392](https://togithub.com/charliermarsh/ruff/pull/3392) - \[`pylint`] C1901: compare-to-empty-string by [@​AreamanM](https://togithub.com/AreamanM) in [https://github.com/charliermarsh/ruff/pull/3405](https://togithub.com/charliermarsh/ruff/pull/3405) - \[`pylint`] Implement W1508 invalid-envvar-default by [@​latonis](https://togithub.com/latonis) in [https://github.com/charliermarsh/ruff/pull/3449](https://togithub.com/charliermarsh/ruff/pull/3449) - \[`pylint`] Implement E1507 invalid-envvar-value by [@​latonis](https://togithub.com/latonis) in [https://github.com/charliermarsh/ruff/pull/3467](https://togithub.com/charliermarsh/ruff/pull/3467) ##### Settings - Infer `target-version` from project metadata by [@​JonathanPlasse](https://togithub.com/JonathanPlasse) in [https://github.com/charliermarsh/ruff/pull/3470](https://togithub.com/charliermarsh/ruff/pull/3470) - Implement configuration options `runtime-evaluated-decorators` and `runtime-evaluated-base-classes` for `flake8-type-checking` by [@​sasanjac](https://togithub.com/sasanjac) in [https://github.com/charliermarsh/ruff/pull/3292](https://togithub.com/charliermarsh/ruff/pull/3292) - Add Azure DevOps as a `--format` option. by [@​StefanBRas](https://togithub.com/StefanBRas) in [https://github.com/charliermarsh/ruff/pull/3335](https://togithub.com/charliermarsh/ruff/pull/3335) ##### Bug Fixes - Re-enable the T and C linter prefix selectors by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3452](https://togithub.com/charliermarsh/ruff/pull/3452) - Treat unary operations on constants as constant-like by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3348](https://togithub.com/charliermarsh/ruff/pull/3348) - Skip byte-order-mark at start of file by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3343](https://togithub.com/charliermarsh/ruff/pull/3343) - Don't enforce typing-import rules in .pyi files by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3362](https://togithub.com/charliermarsh/ruff/pull/3362) - Include entire prefix when reporting rule selector errors by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3375](https://togithub.com/charliermarsh/ruff/pull/3375) - Handle multi-line fixes for byte-string prefixing by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3391](https://togithub.com/charliermarsh/ruff/pull/3391) - Catch RET504 usages via decorators by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3395](https://togithub.com/charliermarsh/ruff/pull/3395) - Ignore multiply-assigned variables in RET504 by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3393](https://togithub.com/charliermarsh/ruff/pull/3393) - \[FIX] PYI011: recognize `Bool` / `Float` / `Complex` numbers as simple defaults by [@​XuehaiPan](https://togithub.com/XuehaiPan) in [https://github.com/charliermarsh/ruff/pull/3459](https://togithub.com/charliermarsh/ruff/pull/3459) - Respect ignores for runtime-import-in-type-checking-block (TCH004) by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3474](https://togithub.com/charliermarsh/ruff/pull/3474) - Avoid panicking in invalid_escape_sequence by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3338](https://togithub.com/charliermarsh/ruff/pull/3338) - fix: Emit a more useful error if an `extend` points at a non-existent ruff.toml file. by [@​DanCardin](https://togithub.com/DanCardin) in [https://github.com/charliermarsh/ruff/pull/3417](https://togithub.com/charliermarsh/ruff/pull/3417) - Respect `--show-fixes` with `--fix-only` by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3426](https://togithub.com/charliermarsh/ruff/pull/3426) - When "Args" and "Parameters" are present, prefer NumPy style by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3430](https://togithub.com/charliermarsh/ruff/pull/3430) - Remove empty line after RUF100 auto-fix by [@​JonathanPlasse](https://togithub.com/JonathanPlasse) in [https://github.com/charliermarsh/ruff/pull/3414](https://togithub.com/charliermarsh/ruff/pull/3414) - Avoid removing un-aliased exceptions in `OSError`-aliased handlers by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3451](https://togithub.com/charliermarsh/ruff/pull/3451) - Use a hash to fingerprint GitLab CI output by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3456](https://togithub.com/charliermarsh/ruff/pull/3456) - Avoid respecting noqa directives when RUF100 is enabled by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3469](https://togithub.com/charliermarsh/ruff/pull/3469) - Output GitLab paths relative to `CI_PROJECT_DIR` by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3475](https://togithub.com/charliermarsh/ruff/pull/3475) - Implement an iterator for universal newlines by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3454](https://togithub.com/charliermarsh/ruff/pull/3454) #### New Contributors - [@​sasanjac](https://togithub.com/sasanjac) made their first contribution in [https://github.com/charliermarsh/ruff/pull/3292](https://togithub.com/charliermarsh/ruff/pull/3292) - [@​aacunningham](https://togithub.com/aacunningham) made their first contribution in [https://github.com/charliermarsh/ruff/pull/3380](https://togithub.com/charliermarsh/ruff/pull/3380) - [@​orf](https://togithub.com/orf) made their first contribution in [https://github.com/charliermarsh/ruff/pull/3389](https://togithub.com/charliermarsh/ruff/pull/3389) - [@​DanCardin](https://togithub.com/DanCardin) made their first contribution in [https://github.com/charliermarsh/ruff/pull/3417](https://togithub.com/charliermarsh/ruff/pull/3417) - [@​AreamanM](https://togithub.com/AreamanM) made their first contribution in [https://github.com/charliermarsh/ruff/pull/3405](https://togithub.com/charliermarsh/ruff/pull/3405) - [@​kyoto7250](https://togithub.com/kyoto7250) made their first contribution in [https://github.com/charliermarsh/ruff/pull/3411](https://togithub.com/charliermarsh/ruff/pull/3411) - [@​latonis](https://togithub.com/latonis) made their first contribution in [https://github.com/charliermarsh/ruff/pull/3449](https://togithub.com/charliermarsh/ruff/pull/3449) - [@​XuehaiPan](https://togithub.com/XuehaiPan) made their first contribution in [https://github.com/charliermarsh/ruff/pull/3459](https://togithub.com/charliermarsh/ruff/pull/3459) - [@​CalumY](https://togithub.com/CalumY) made their first contribution in [https://github.com/charliermarsh/ruff/pull/3461](https://togithub.com/charliermarsh/ruff/pull/3461) - [@​YDX-2147483647](https://togithub.com/YDX-2147483647) made their first contribution in [https://github.com/charliermarsh/ruff/pull/3473](https://togithub.com/charliermarsh/ruff/pull/3473) **Full Changelog**: astral-sh/ruff@v0.0.254...v0.0.255 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/allenporter/flux-local). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4xNjAuMCIsInVwZGF0ZWRJblZlciI6IjM0LjE2MC4wIn0=--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
hey, i encountered this rule just now and i think its problematic, take the following example:
which outputs:
running so following this suggestion creates code that doesnt differentiate between |
Yeah this is a known limitation of this rule unfortunately -- see, e.g., #3503. Pylint has the same problem. I've considered removing it for this reason. You can restructure your code in various ways to ignore the lint, or disable the rule, but the rule itself can't really be improved without being made useless: def foo(a: str | None):
if a is None:
print('none')
if not a:
print('empty string') Or: def foo(a: str | None):
if not a:
if isinstance(a, str):
print('empty string')
else:
print('none') (I'm not suggesting that these are better in any subjective sense, only that they avoid the issue.) |
Going to echo that I think the rule is a bit of an issue. My team prefers to declare falsey values explicitly to avoid being unsure of Thanks |
There's a few finishing touches left to make(docs, diagnostic message, make the logic a little cleaner) and I think this is autofixable, so if the diagnostic impl itself looks good, I'll have a go at autofix for this as well.