Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: astral-sh/ruff
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: refs/tags/0.9.0
Choose a base ref
...
head repository: astral-sh/ruff
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0.9.1
Choose a head ref
  • 16 commits
  • 54 files changed
  • 12 contributors

Commits on Jan 9, 2025

  1. [pycodestyle] Handle each cell separately for `too-many-newlines-at…

    …-end-of-file` (`W391`) (#15308)
    
    Jupyter notebooks are converted into source files by joining with
    newlines, which confuses the check [too-many-newlines-at-end-of-file
    (W391)](https://docs.astral.sh/ruff/rules/too-many-newlines-at-end-of-file/#too-many-newlines-at-end-of-file-w391).
    This PR introduces logic to apply the check cell-wise (and, in
    particular, correctly handles empty cells.)
    
    Closes #13763
    dylwil3 authored Jan 9, 2025
    Configuration menu
    Copy the full SHA
    b0905c4 View commit details
    Browse the repository at this point in the history
  2. [red-knot] Move UnionBuilder tests to Markdown (#15374)

    ## Summary
    
    This moves almost all of our existing `UnionBuilder` tests to a
    Markdown-based test suite.
    
    I see how this could be a more controversial change, since these tests
    where written specifically for `UnionBuilder`, and by creating the union
    types using Python type expressions, we add an additional layer on top
    (parsing and inference of these expressions) that moves these tests away
    from clean unit tests more in the direction of integration tests. Also,
    there are probably a few implementation details of `UnionBuilder` hidden
    in the test assertions (e.g. order of union elements after
    simplifications).
    
    That said, I think we would like to see all those properties that are
    being tested here from *any* implementation of union types. And the
    Markdown tests come with the usual advantages:
    
    - More consice
    - Better readability
    - No re-compiliation when working on tests
    - Easier to add additional explanations and structure to the test suite
    
    This changeset adds a few additional tests, but keeps the logic of the
    existing tests except for a few minor modifications for consistency.
    
    ---------
    
    Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
    Co-authored-by: T-256 <132141463+T-256@users.noreply.github.com>
    3 people authored Jan 9, 2025
    Configuration menu
    Copy the full SHA
    b33cf5b View commit details
    Browse the repository at this point in the history

Commits on Jan 10, 2025

  1. [red-knot] Consolidate all gradual types into single Type variant (#1…

    …5386)
    
    Prompted by
    
    > One nit: I think we need to consider `Any` and `Unknown` and `Todo` as
    all (gradually) equivalent to each other, and thus `type & Any` and
    `type & Unknown` and `type & Todo` as also equivalent. The distinction
    between `Any` vs `Unknown` vs `Todo` is entirely about
    provenance/debugging, there is no type level distinction. (And I've been
    wondering if the `Any` vs `Unknown` distinction is really worth it.)
    
    The thought here is that _most_ places want to treat `Any`, `Unknown`,
    and `Todo` identically. So this PR simplifies things by having a single
    `Type::Any` variant, and moves the provenance part into a new `AnyType`
    type. If you need to treat e.g. `Todo` differently, you still can by
    pattern-matching into the `AnyType`. But if you don't, you can just use
    `Type::Any(_)`.
    
    (This would also allow us to (more easily) distinguish "unknown via an
    unannotated value" from "unknown because of a typing error" should we
    want to do that in the future)
    
    ---------
    
    Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
    Co-authored-by: Carl Meyer <carl@astral.sh>
    3 people authored Jan 10, 2025
    Configuration menu
    Copy the full SHA
    baf0683 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    3d9433c View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    23ad319 View commit details
    Browse the repository at this point in the history
  4. [ruff] Omit diagnostic for shadowed private function parameters in …

    …`used-dummy-variable` (`RUF052`) (#15376)
    dylwil3 authored Jan 10, 2025
    Configuration menu
    Copy the full SHA
    443bf38 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    b861551 View commit details
    Browse the repository at this point in the history
  6. [red-knot] Move intersection type tests to Markdown (#15396)

    ## Summary
    
    [**Rendered version of the new test
    suite**](https://github.com/astral-sh/ruff/blob/david/intersection-type-tests/crates/red_knot_python_semantic/resources/mdtest/intersection_types.md)
    
    Moves most of our existing intersection-types tests to a dedicated
    Markdown test suite, extends the test coverage, unifies the notation for
    these tests, groups tests into a proper structure, and adds some
    explanations for various simplification strategies.
    
    This changeset also:
    - Adds a new simplification where `~Never` is removed from
    intersections.
    - Adds a new simplification where adding `~object` simplifies the whole
    intersection to `Never`
    - Avoids unnecessary assignment-checks between inferred and declared
    type. This was added to this changeset to avoid many false positive
    errors in this test suite.
    
    Resolves the task described in this old comment
    [here](https://github.com/astral-sh/ruff/pull/13962/files/e01da82a5a0ef6a2af0aa4dc50f898cffadb4a33..e7e432bca2b3f24979da55a9a34ad765aaaae8d1#r1819924085).
    
    ## Test Plan
    
    Running the new Markdown tests
    
    ---------
    
    Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
    sharkdp and AlexWaygood authored Jan 10, 2025
    Configuration menu
    Copy the full SHA
    f2c3ddc View commit details
    Browse the repository at this point in the history
  7. Insert the cells from the start position (#15398)

    ## Summary
    
    The cause of this bug is from
    #12575 which was itself a bug fix
    but the fix wasn't completely correct.
    
    fixes: #14768 
    fixes: astral-sh/ruff-vscode#644
    
    ## Test Plan
    
    Consider the following three cells:
    
    1.
    ```python
    class Foo:
        def __init__(self):
            self.x = 1
    
        def __str__(self):
            return f"Foo({self.x})"
    ```
    
    2.
    ```python
    def hello():
        print("hello world")
    ```
    
    3.
    ```python
    y = 1
    ```
    
    The test case is moving cell 2 to the top i.e., cell 2 goes to position
    1 and cell 1 goes to position 2.
    
    Before this fix, it can be seen that the cells were pushed at the end of
    the vector:
    
    ```
      12.643269917s  INFO ruff:main ruff_server::edit::notebook: Before update: [
        NotebookCell {
            document: TextDocument {
                contents: "class Foo:\n    def __init__(self):\n        self.x = 1\n\n    def __str__(self):\n        return f\"Foo({self.x})\"",
            },
        },
        NotebookCell {
            document: TextDocument {
                contents: "def hello():\n    print(\"hello world\")",
            },
        },
        NotebookCell {
            document: TextDocument {
                contents: "y = 1",
            },
        },
    ]
      12.643777667s  INFO ruff:main ruff_server::edit::notebook: After update: [
        NotebookCell {
            document: TextDocument {
                contents: "y = 1",
            },
        },
        NotebookCell {
            document: TextDocument {
                contents: "class Foo:\n    def __init__(self):\n        self.x = 1\n\n    def __str__(self):\n        return f\"Foo({self.x})\"",
            },
        },
        NotebookCell {
            document: TextDocument {
                contents: "def hello():\n    print(\"hello world\")",
            },
        },
    ]
    ```
    
    After the fix in this PR, it can be seen that the cells are being pushed
    at the correct `start` index:
    
    ```
       6.520570917s  INFO ruff:main ruff_server::edit::notebook: Before update: [
        NotebookCell {
            document: TextDocument {
                contents: "class Foo:\n    def __init__(self):\n        self.x = 1\n\n    def __str__(self):\n        return f\"Foo({self.x})\"",
            },
        },
        NotebookCell {
            document: TextDocument {
                contents: "def hello():\n    print(\"hello world\")",
            },
        },
        NotebookCell {
            document: TextDocument {
                contents: "y = 1",
            },
        },
    ]
       6.521084792s  INFO ruff:main ruff_server::edit::notebook: After update: [
        NotebookCell {
            document: TextDocument {
                contents: "def hello():\n    print(\"hello world\")",
            },
        },
        NotebookCell {
            document: TextDocument {
                contents: "class Foo:\n    def __init__(self):\n        self.x = 1\n\n    def __str__(self):\n        return f\"Foo({self.x})\"",
            },
        },
        NotebookCell {
            document: TextDocument {
                contents: "y = 1",
            },
        },
    ]
    ```
    dhruvmanila authored Jan 10, 2025
    Configuration menu
    Copy the full SHA
    6e9ff44 View commit details
    Browse the repository at this point in the history
  8. Fix outdated doc for handling the default file types with the pre-com…

    …mit hook (#15401)
    
    Co-authored-by: Antoine DECHAUME <>
    AntoineD authored Jan 10, 2025
    Configuration menu
    Copy the full SHA
    73d424e View commit details
    Browse the repository at this point in the history
  9. [flake8-pie] Correctly remove wrapping parentheses (PIE800) (#15394)

    Co-authored-by: Micha Reiser <micha@reiser.io>
    InSyncWithFoo and MichaReiser authored Jan 10, 2025
    Configuration menu
    Copy the full SHA
    c364b58 View commit details
    Browse the repository at this point in the history
  10. [red-knot] Move tuple-containing-Never tests to Markdown (#15402)

    ## Summary
    
    See title.
    
    Part of #15397
    
    ## Test Plan
    
    Ran new Markdown test.
    
    ---------
    
    Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
    sharkdp and AlexWaygood authored Jan 10, 2025
    Configuration menu
    Copy the full SHA
    c874638 View commit details
    Browse the repository at this point in the history
  11. [red-knot] Support assert_type (#15194)

    ## Summary
    
    See #15103.
    
    ## Test Plan
    
    Markdown tests and unit tests.
    InSyncWithFoo authored Jan 10, 2025
    Configuration menu
    Copy the full SHA
    6b98a26 View commit details
    Browse the repository at this point in the history
  12. Remove pygments pin (#15404)

    ## Summary
    
    The recent release of Pygments
    ([2.19.1](https://github.com/pygments/pygments/releases/tag/2.19.1))
    allows the pinned version to be removed as the PYI alias for Python
    syntax highlighting has been removed.
    
    ## Test Plan
    
    - Follow the steps outlined in
    https://github.com/astral-sh/ruff/blob/main/CONTRIBUTING.md#mkdocs to
    get the documentation site running locally.
    - Spot test rules pages that have PYI code blocks to ensure that syntax
    highlighting remains e.g.
    [http://127.0.0.1:8000/ruff/rules/complex-if-statement-in-stub/](http://127.0.0.1:8000/ruff/rules/complex-if-statement-in-stub/).
    
    **Note:** I am unable to test the insiders build but would assume that
    it functions locally as I do not have access to MkDocs Insiders, but I
    would like to assume that it functions in the same way as the
    non-insiders build.
    calumy authored Jan 10, 2025
    Configuration menu
    Copy the full SHA
    adca7bd View commit details
    Browse the repository at this point in the history
  13. Associate a trailing end-of-line comment in a parenthesized implicit …

    …concatenated string with the last literal (#15378)
    MichaReiser authored Jan 10, 2025
    Configuration menu
    Copy the full SHA
    2b28d56 View commit details
    Browse the repository at this point in the history
  14. Ruff 0.9.1 (#15407)

    MichaReiser authored Jan 10, 2025
    Configuration menu
    Copy the full SHA
    12f86f3 View commit details
    Browse the repository at this point in the history
Loading