-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Comparing changes
Open a pull request
base repository: astral-sh/ruff
base: 0.11.1
head repository: astral-sh/ruff
compare: 0.11.2
- 9 commits
- 32 files changed
- 7 contributors
Commits on Mar 20, 2025
-
[red-knot] add test cases result in false positive errors (#16856)
## Summary From #16641 The previous PR attempted to fix the errors presented in this PR, but as discussed in the conversation, it was concluded that the approach was undesirable and that further work would be needed to fix the errors with a correct general solution. In this PR, I instead add the test cases from the previous PR as TODOs, as a starting point for future work. ## Test Plan --------- Co-authored-by: Carl Meyer <carl@oddbird.net>
Configuration menu - View commit details
-
Copy full SHA for 23382f5 - Browse repository at this point
Copy the full SHA 23382f5View commit details -
Recognize
SyntaxError:
as an error code for ecosystem checks (#16879)Summary -- This updates the regex in `ruff-ecosystem` to catch syntax errors in an effort to prevent bugs like #16874. This should catch `ParseError`s, `UnsupportedSyntaxError`s, and the upcoming `SemanticSyntaxError`s. Test Plan -- I ran the ecosystem check locally comparing v0.11.0 and v0.11.1 and saw a large number (2757!) of new syntax errors. I also manually tested the regex on a few lines before that. If we merge this before #16878, I'd expect to see that number decrease substantially in that PR too, as another test.
Configuration menu - View commit details
-
Copy full SHA for 6760251 - Browse repository at this point
Copy the full SHA 6760251View commit details -
[syntax-errors] Fix star annotation before Python 3.11 (#16878)
Summary -- Fixes #16874. I previously emitted a syntax error when starred annotations were _allowed_ rather than when they were actually used. This caused false positives for any starred parameter name because these are allowed to have starred annotations but not required to. The fix is to check if the annotation is actually starred after parsing it. Test Plan -- New inline parser tests derived from the initial report and more examples from the comments, although I think the first case should cover them all.
Configuration menu - View commit details
-
Copy full SHA for 42cbce5 - Browse repository at this point
Copy the full SHA 42cbce5View commit details -
Special-case value-expression inference of special form subscriptions (…
…#16877) ## Summary Currently for something like `X = typing.Tuple[str, str]`, we infer the value of `X` as `object`. That's because `Tuple` (like many of the symbols in the typing module) is annotated as a `_SpecialForm` instance in typeshed's stubs: https://github.com/astral-sh/ruff/blob/23382f5f8c7b4e356368cdeb1049b8c1910baff3/crates/red_knot_vendored/vendor/typeshed/stdlib/typing.pyi#L215 and we don't understand implicit type aliases yet, and the stub for `_SpecialForm.__getitem__` says it always returns `object`: https://github.com/astral-sh/ruff/blob/23382f5f8c7b4e356368cdeb1049b8c1910baff3/crates/red_knot_vendored/vendor/typeshed/stdlib/typing.pyi#L198-L200 We have existing false positives in our test suite due to this: https://github.com/astral-sh/ruff/blob/23382f5f8c7b4e356368cdeb1049b8c1910baff3/crates/red_knot_python_semantic/resources/mdtest/annotations/annotated.md?plain=1#L76-L78 and it's causing _many_ new false positives in #16872, which tries to make our annotation-expression parsing stricter in some ways. This PR therefore adds some small special casing for `KnownInstanceType` variants that fallback to `_SpecialForm`, so that these false positives can be avoided. ## Test Plan Existing mdtest altered. Cc. @MatthewMckee4
Configuration menu - View commit details
-
Copy full SHA for 296d67a - Browse repository at this point
Copy the full SHA 296d67aView commit details -
[red-knot] Ban most
Type::Instance
types in type expressions (#16872)## Summary Catch some Instances, but raise type error for the rest of them Fixes #16851 ## Test Plan Extend invalid.md in annotations --------- Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Configuration menu - View commit details
-
Copy full SHA for 63e78b4 - Browse repository at this point
Copy the full SHA 63e78b4View commit details
Commits on Mar 21, 2025
-
[red-knot] Check whether two callable types are equivalent (#16698)
## Summary This PR checks whether two callable types are equivalent or not. This is required because for an equivalence relationship, the default value does not necessarily need to be the same but if the parameter in one of the callable has a default value then the corresponding parameter in the other callable should also have a default value. This is the main reason a manual implementation is required. And, as per https://typing.python.org/en/latest/spec/callables.html#id4, the default _type_ doesn't participate in a subtype relationship, only the optionality (required or not) participates. This means that the following two callable types are equivalent: ```py def f1(a: int = 1) -> None: ... def f2(a: int = 2) -> None: ... ``` Additionally, the name of positional-only, variadic and keyword-variadic are not required to be the same for an equivalence relation. A potential solution to avoid the manual implementation would be to only store whether a parameter has a default value or not but the type is currently required to check for assignability. ## Test plan Add tests for callable types in `is_equivalent_to.md`
Configuration menu - View commit details
-
Copy full SHA for 193c381 - Browse repository at this point
Copy the full SHA 193c381View commit details -
[red-knot] Check subtype relation between callable types (#16804)
## Summary Part of #15382 This PR adds support for checking the subtype relationship between the two callable types. The main source of reference used for implementation is https://typing.python.org/en/latest/spec/callables.html#assignability-rules-for-callables. The implementation is split into two phases: 1. Check all the positional parameters which includes positional-only, standard (positional or keyword) and variadic kind 2. Collect all the keywords in a `HashMap` to do the keyword parameters check via name lookup For (1), there's a helper struct which is similar to `.zip_longest` (from `itertools`) except that it allows control over one of the iterator as that's required when processing a variadic parameter. This is required because positional parameters needs to be checked as per their position between the two callable types. The struct also keeps track of the current iteration element because when the loop is exited (to move on to the phase 2) the current iteration element would be carried over to the phase 2 check. This struct is internal to the `is_subtype_of` method as I don't think it makes sense to expose it outside. It also allows me to use "self" and "other" suffixed field names as that's only relevant in that context. ## Test Plan Add extensive tests in markdown. Converted all of the code snippets from https://typing.python.org/en/latest/spec/callables.html#assignability-rules-for-callables to use `knot_extensions.is_subtype_of` and verified the result.
Configuration menu - View commit details
-
Copy full SHA for 04a8756 - Browse repository at this point
Copy the full SHA 04a8756View commit details -
Use the common
OperatorPrecedence
for the parser (#16747)## Summary This change continues to resolve #16071 (and continues the work started in #16162). Specifically, this PR changes the code in the parser so that it uses the `OperatorPrecedence` struct from `ruff_python_ast` instead of its own version. This is part of an effort to get rid of the redundant definitions of `OperatorPrecedence` throughout the codebase. Note that this PR only makes this change for `ruff_python_parser` -- we still want to make a similar change for the formatter (namely the `OperatorPrecedence` defined in the expression part of the formatter, the pattern one is different). I separated the work to keep the PRs small and easily reviewable. ## Test Plan Because this is an internal change, I didn't add any additional tests. Existing tests do pass.
Configuration menu - View commit details
-
Copy full SHA for 2a4d835 - Browse repository at this point
Copy the full SHA 2a4d835View commit details -
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Configuration menu - View commit details
-
Copy full SHA for 4773878 - Browse repository at this point
Copy the full SHA 4773878View 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 0.11.1...0.11.2