-
Notifications
You must be signed in to change notification settings - Fork 2k
Comparing changes
Open a pull request
base repository: astral-sh/ruff
base: v0.3.1
head repository: astral-sh/ruff
compare: v0.3.2
- 14 commits
- 188 files changed
- 6 contributors
Commits on Mar 7, 2024
-
Avoid repeating function calls in f-string conversions (#10265)
## Summary Given a format string like `"{x} {x}".format(x=foo())`, we should avoid converting to an f-string, since doing so would require repeating the function call (`f"{foo()} {foo()}"`), which could introduce side effects. Closes #10258.Configuration menu - View commit details
-
Copy full SHA for 461cdad - Browse repository at this point
Copy the full SHA 461cdadView commit details -
[
pyupgrade] Allow fixes for f-string rule regardless of line length…… (`UP032`) (#10263) ## Summary This is a follow-up to #10238 to offer fixes for the f-string rule regardless of the line length of the resulting fix. To quote Alex in the linked PR: > Yes, from the user's perspective I'd rather have a fix that may lead to line length issues than have to fix them myself :-) Cleaning up line lengths is easier than changing from `"".format()` to `f""` I agree with this position, which is that if we're going to offer a diagnostic, we should really be offering the user the ability to fix it -- otherwise, we're just inconveniencing them.
Configuration menu - View commit details
-
Copy full SHA for 91af5a4 - Browse repository at this point
Copy the full SHA 91af5a4View commit details -
Fix E203 false positive for slices in format strings (#10280)
## Summary The code later in this file that checks for slices relies on the stack of brackets to determine the position. I'm not sure why format strings were being excluded from this, but the tests still pass with these match guards removed. Closes #10278 ## Test Plan ~Still needs a test.~ Test case added for this example.
Configuration menu - View commit details
-
Copy full SHA for 7b4a73d - Browse repository at this point
Copy the full SHA 7b4a73dView commit details
Commits on Mar 8, 2024
-
## Summary As of https://github.com/pypa/gh-action-pypi-publish/releases/tag/v1.8.13, all relevant dependencies have been updated to support Metadata 2.2, so we can remove our Maturin pin.
Configuration menu - View commit details
-
Copy full SHA for 7a675cd - Browse repository at this point
Copy the full SHA 7a675cdView commit details -
Treat
typing.Annotatedsubscripts as type definitions (#10285)Configuration menu - View commit details
-
Copy full SHA for 57be3fc - Browse repository at this point
Copy the full SHA 57be3fcView commit details -
Include actual conditions in E712 diagnostics (#10254)
## Summary Changes the generic recommendation to replace ```python if foo == True: ... ``` with `if cond:` to `if foo:`. Still uses a generic message for compound comparisons as a specific message starts to become confusing. For example, ```python if foo == True != False: ... ``` produces two recommendations, one of which would recommend `if True:`, which is confusing. Resolves [recommendation in a previous PR](https://github.com/astral-sh/ruff/pull/8613/files#r1514915070). ## Test Plan `cargo nextest run`
Configuration menu - View commit details
-
Copy full SHA for 72c9f7e - Browse repository at this point
Copy the full SHA 72c9f7eView commit details -
Configuration menu - View commit details
-
Copy full SHA for c504d7a - Browse repository at this point
Copy the full SHA c504d7aView commit details -
Fix trailing kwargs end of line comment after slash (#10297)
## Summary Fixes the handling end of line comments that belong to `**kwargs` when the `**kwargs` come after a slash. The issue was that we missed to include the `**kwargs` start position when determining the start of the next node coming after the `/`. Fixes #10281 ## Test Plan Added test
Configuration menu - View commit details
-
Copy full SHA for 965adbe - Browse repository at this point
Copy the full SHA 965adbeView commit details -
Start tracking quoting style in the AST (#10298)
This PR modifies our AST so that nodes for string literals, bytes literals and f-strings all retain the following information: - The quoting style used (double or single quotes) - Whether the string is triple-quoted or not - Whether the string is raw or not This PR is a followup to #10256. Like with that PR, this PR does not, in itself, fix any bugs. However, it means that we will have the necessary information to preserve quoting style and rawness of strings in the `ExprGenerator` in a followup PR, which will allow us to provide a fix for #7799. The information is recorded on the AST nodes using a bitflag field on each node, similarly to how we recorded the information on `Tok::String`, `Tok::FStringStart` and `Tok::FStringMiddle` tokens in #10298. Rather than reusing the bitflag I used for the tokens, however, I decided to create a custom bitflag for each AST node. Using different bitflags for each node allows us to make invalid states unrepresentable: it is valid to set a `u` prefix on a string literal, but not on a bytes literal or an f-string. It also allows us to have better debug representations for each AST node modified in this PR.
Configuration menu - View commit details
-
Copy full SHA for 1d97f27 - Browse repository at this point
Copy the full SHA 1d97f27View commit details -
Refactor with statement formatting to have explicit layouts (#10296)
## Summary This PR refactors the with item formatting to use more explicit layouts to make it easier to understand the different formatting cases. The benefit of the explicit layout is that it makes it easier to reasons about layout transition between format runs. For example, today it's possible that `SingleWithTarget` or `ParenthesizeIfExpands` add parentheses around the with items for `with aaaaaaaaaa + bbbbbbbbbbbb: pass`, resulting in `with (aaaaaaaaaa + bbbbbbbbbbbb): pass`. The problem with this is that the next formatting pass uses the `SingleParenthesizedContextExpression` layout that uses `maybe_parenthesize_expression` which is different from `parenthesize_if_expands(&expr)` or `optional_parentheses(&expr)`. ## Test Plan `cargo test` I ran the ecosystem checks locally and there are no changes.
Configuration menu - View commit details
-
Copy full SHA for a56d42f - Browse repository at this point
Copy the full SHA a56d42fView commit details -
Fix unstable with-items formatting (#10274)
## Summary Fixes #10267 The issue with the current formatting is that the formatter flips between the `SingleParenthesizedContextManager` and `ParenthesizeIfExpands` or `SingleWithTarget` because the layouts use incompatible formatting ( `SingleParenthesizedContextManager`: `maybe_parenthesize_expression(context)` vs `ParenthesizeIfExpands`: `parenthesize_if_expands(item)`, `SingleWithTarget`: `optional_parentheses(item)`. The fix is to ensure that the layouts between which the formatter flips when adding or removing parentheses are the same. I do this by introducing a new `SingleWithoutTarget` layout that uses the same formatting as `SingleParenthesizedContextManager` if it has no target and prefer `SingleWithoutTarget` over using `ParenthesizeIfExpands` or `SingleWithTarget`. ## Formatting change The downside is that we now use `maybe_parenthesize_expression` over `parenthesize_if_expands` for expressions where `can_omit_optional_parentheses` returns `false`. This can lead to stable formatting changes. I only found one formatting change in our ecosystem check and, unfortunately, this is necessary to fix the instability (and instability fixes are okay to have as part of minor changes according to our versioning policy) The benefit of the change is that `with` items with a single context manager and without a target are now formatted identically to how the same expression would be formatted in other clause headers. ## Test Plan I ran the ecosystem check locally
Configuration menu - View commit details
-
Copy full SHA for 4bce801 - Browse repository at this point
Copy the full SHA 4bce801View commit details -
Formatter: Improve single-with item formatting for Python 3.8 or older (
#10276) ## Summary This PR changes how we format `with` statements with a single with item for Python 3.8 or older. This change is not compatible with Black. This is how we format a single-item with statement today ```python def run(data_path, model_uri): with pyspark.sql.SparkSession.builder.config( key="spark.python.worker.reuse", value=True ).config(key="spark.ui.enabled", value=False).master( "local-cluster[2, 1, 1024]" ).getOrCreate(): # ignore spark log output spark.sparkContext.setLogLevel("OFF") print(score_model(spark, data_path, model_uri)) ``` This is different than how we would format the same expression if it is inside any other clause header (`while`, `if`, ...): ```python def run(data_path, model_uri): while ( pyspark.sql.SparkSession.builder.config( key="spark.python.worker.reuse", value=True ) .config(key="spark.ui.enabled", value=False) .master("local-cluster[2, 1, 1024]") .getOrCreate() ): # ignore spark log output spark.sparkContext.setLogLevel("OFF") print(score_model(spark, data_path, model_uri)) ``` Which seems inconsistent to me. This PR changes the formatting of the single-item with Python 3.8 or older to match that of other clause headers. ```python def run(data_path, model_uri): with ( pyspark.sql.SparkSession.builder.config( key="spark.python.worker.reuse", value=True ) .config(key="spark.ui.enabled", value=False) .master("local-cluster[2, 1, 1024]") .getOrCreate() ): # ignore spark log output spark.sparkContext.setLogLevel("OFF") print(score_model(spark, data_path, model_uri)) ``` According to our versioning policy, this style change is gated behind a preview flag. ## Test Plan See added tests. Added
Configuration menu - View commit details
-
Copy full SHA for b64f2ea - Browse repository at this point
Copy the full SHA b64f2eaView commit details -
Fix incorrect
Parameterrange for*argsand**kwargs(#10283)## Summary Fix #10282 This PR updates the Python grammar to include the `*` character in `*args` `**kwargs` in the range of the `Parameter` ``` def f(*args, **kwargs): pass # ~~~~ ~~~~~~ <-- range before the PR # ^^^^^ ^^^^^^^^ <-- range after ``` The invalid syntax `def f(*, **kwargs): ...` is also now correctly reported. ## Test Plan Test cases were added to `function.rs`.
Configuration menu - View commit details
-
Copy full SHA for a067d87 - Browse repository at this point
Copy the full SHA a067d87View commit details
Commits on Mar 9, 2024
-
Configuration menu - View commit details
-
Copy full SHA for a892fc7 - Browse repository at this point
Copy the full SHA a892fc7View commit details
This comparison is taking too long to generate.
Unfortunately it looks like we can’t render this comparison for you right now. It might be too big, or there might be something weird with your repository.
You can try running this command locally to see the comparison on your machine:
git diff v0.3.1...v0.3.2