-
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
[flake8-bugbear] Consider replacing f"'{foo}'" with f"{foo!r}" which is both easier to read and will escape quotes inside foo if that would appear (B907) #13600
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Fixes #3758 Implement B903 and B907 flake8-bugbear rules in Ruff. * Add `crates/ruff_linter/src/rules/flake8_bugbear/rules/b903.rs` to implement B903 rule for data classes that only set attributes in an `__init__` method. * Add `crates/ruff_linter/src/rules/flake8_bugbear/rules/b907.rs` to implement B907 rule to replace f"'{foo}'" with f"{foo!r}". * Update `crates/ruff_linter/src/rules/flake8_bugbear/mod.rs` to include B903 and B907 rules. * Add test cases for B903 and B907 rules in `crates/ruff_linter/src/rules/flake8_bugbear/tests.rs`.
* **New Rules** - Add `UseDataclassesForDataClasses` variant to `Rule` enum - Add `FStringSingleQuotes` variant to `Rule` enum
* **Update `Rule` enum** - Add `UseDataclassesForDataClasses` for B903 - Add `FStringSingleQuotes` for B907 * **Update imports in `mod.rs`** - Add `use_dataclasses_for_data_classes::*` - Add `f_string_single_quotes::*`
## Summary fixes: #13603
…collections.abc.AsyncGenerator` (#13611) ## Summary fix #13602 Currently, `UP043` only applies to typing.Generator, but it should also support collections.abc.Generator. This update ensures `UP043` correctly handles both `collections.abc.Generator` and `collections.abc.AsyncGenerator` ### UP043 > `UP043` > Python 3.13 introduced the ability for type parameters to specify default values. As such, the default type arguments for some types in the standard library (e.g., Generator, AsyncGenerator) are now optional. > Omitting type parameters that match the default values can make the code more concise and easier to read. ```py Generator[int, None, None] -> Generator[int] ```
https://github.com/pre-commit/mirrors-prettier has been archived and is no longer maintained. Signed-off-by: Bernát Gábor <[email protected]>
Closes #13545 As described in the issue, we move comments before the inner `if` statement to before the newly constructed `elif` statement (previously `else`).
Resolves #13321. Contents of overlay: ```bash /private/var/folders/v0/l8q3ghks2gs5ns2_p63tyqh40000gq/T/pip-build-env-e0ukpbvo/overlay/bin: total 26M -rwxr-xr-x 1 bgabor8 staff 26M Oct 1 08:22 ruff drwxr-xr-x 3 bgabor8 staff 96 Oct 1 08:22 . drwxr-xr-x 4 bgabor8 staff 128 Oct 1 08:22 .. ``` Python executable: ```bash '/Users/bgabor8/git/github/ruff-find-bin-during-build/.venv/bin/python' ``` PATH is: ```bash ['/private/var/folders/v0/l8q3ghks2gs5ns2_p63tyqh40000gq/T/pip-build-env-e0ukpbvo/overlay/bin', '/private/var/folders/v0/l8q3ghks2gs5ns2_p63tyqh40000gq/T/pip-build-env-e0ukpbvo/normal/bin', '/Library/Frameworks/Python.framework/Versions/3.11/bin', '/Library/Frameworks/Python.framework/Versions/3.12/bin', ``` Not sure where to add tests, there does not seem to be any existing one. Can someone help me with that?
…13601) ## Summary Resolves #9962 by allowing a configuration setting `allowed-unused-imports` TODO: - [x] Figure out the correct name and place for the setting; currently, I have added it top level. - [x] The comparison is pretty naive. I tried using `glob::Pattern` but couldn't get it to work in the configuration. - [x] Add tests - [x] Update documentations ## Test Plan `cargo test`
FYI, there's another implementation of |
Thanks @dhruvmanila. I'll remove the B903 implementation and instead create a PR for B907 |
## Summary Implements the comparison operator for `[Type::IntLiteral]` and `[Type::BooleanLiteral]` (as an artifact of special handling of `True` and `False` in python). Sets the framework to implement more comparison for types known at static time (e.g. `BooleanLiteral`, `StringLiteral`), allowing us to only implement cases of the triplet `<left> Type`, `<right> Type`, `CmpOp`. Contributes to #12701 (without checking off an item yet). ## Test Plan - Added a test for the comparison of literals that should include most cases of note. - Added a test for the comparison of int instances Please note that the cases do not cover 100% of the branches as there are many and the current testing strategy with variables make this fairly confusing once we have too many in one test. --------- Co-authored-by: Carl Meyer <[email protected]> Co-authored-by: Alex Waygood <[email protected]>
As discussed in #13619
Closes #13343 --------- Co-authored-by: Alex Waygood <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
## Summary fixes: #13718 ## Test Plan Using the notebook as mentioned in #13718 (comment), this PR does not give the "F821 Undefined name `test_sorted`" diagnostic.
Co-authored-by: Micha Reiser <[email protected]>
Implements inference for `BytesLiteral` comparisons along the lines of #13634. closes #13687 Co-authored-by: Alex Waygood <[email protected]>
…ument pitfalls of using `rstest` in combination with `mdtest` (#13747)
This is a follow-up on #13746: - Use `memmem::find` instead of rolling our own inferior version. - Avoid `x.as_ref()` calls using `&**x`
Fixes #3758 Implement B903 and B907 flake8-bugbear rules in Ruff. * Add `crates/ruff_linter/src/rules/flake8_bugbear/rules/b903.rs` to implement B903 rule for data classes that only set attributes in an `__init__` method. * Add `crates/ruff_linter/src/rules/flake8_bugbear/rules/b907.rs` to implement B907 rule to replace f"'{foo}'" with f"{foo!r}". * Update `crates/ruff_linter/src/rules/flake8_bugbear/mod.rs` to include B903 and B907 rules. * Add test cases for B903 and B907 rules in `crates/ruff_linter/src/rules/flake8_bugbear/tests.rs`.
* **New Rules** - Add `UseDataclassesForDataClasses` variant to `Rule` enum - Add `FStringSingleQuotes` variant to `Rule` enum
* **Update `Rule` enum** - Add `UseDataclassesForDataClasses` for B903 - Add `FStringSingleQuotes` for B907 * **Update imports in `mod.rs`** - Add `use_dataclasses_for_data_classes::*` - Add `f_string_single_quotes::*`
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
B907: Consider replacing f"'{foo}'" with f"{foo!r}" which is both easier to read and will escape quotes inside foo if that would appear. The check tries to filter out any format specs that are invalid together with !r. If you’re using other conversion flags then e.g. f"'{foo!a}'" can be replaced with f"{ascii(foo)!r}". Not currently implemented for python<3.8 or str.format() calls.
Implement B907 flake8-bugbear rules in Ruff.
crates/ruff_linter/src/rules/flake8_bugbear/rules/b907.rs
to implement B907 rule to replace f"'{foo}'" with f"{foo!r}".crates/ruff_linter/src/rules/flake8_bugbear/mod.rs
to include B907 rules.crates/ruff_linter/src/rules/flake8_bugbear/tests.rs
.