Skip to content

Conversation

@bellini666
Copy link
Member

@bellini666 bellini666 commented Oct 22, 2025

#4032 was sorting imports wrong, so I added our integrations as "known third party"

Summary by Sourcery

Update pre-commit hooks and import sorting configuration, and apply related code and test adjustments to conform to the new linting rules.

Enhancements:

  • Add FastAPI, Pydantic, Litestar, Aiohttp, Channels, Sanic, Chalice, and Quart as known third-party libraries in isort configuration to correct import ordering

Build:

  • Bump ruff to 0.14.1 and blacken-docs to 1.20.0 in pre-commit hooks and align dev dependencies in pyproject.toml

Tests:

  • Normalize import grouping in tests, add blank lines before Strawberry imports, rename unused variables with underscores, and convert regex matches to raw strings

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 22, 2025

Reviewer's Guide

This PR bumps pre-commit hook versions and updates isort settings to treat all Strawberry framework integrations as known third-party, then applies automated formatting across the codebase, modernizes several type annotations to PEP 604 unions, reorders class inheritance for style consistency, and cleans up test files (blank lines, regex strings, variable naming) to align with the new linting rules.

File-Level Changes

Change Details Files
Bump pre-commit hooks and linter dependencies
  • Upgrade ruff version in pyproject.toml and .pre-commit-config.yaml
  • Upgrade blacken-docs version in .pre-commit-config.yaml
pyproject.toml
.pre-commit-config.yaml
Extend isort known-third-party list for all integrations
  • Add fastapi, pydantic, litestar, aiohttp, channels, sanic, chalice, quart to known-third-party
pyproject.toml
Modernize type annotations and reorder class inheritance
  • Switch init params from Literal[...,None] to Literal[...,]
None
  • Reorder AbstractCache and Protocol inheritors to place ABC/Protocol first
  • Clean up test files for blank lines, regex patterns, and unused variables
    • Insert blank lines after imports across various test modules
    • Rename unused tuple unpack vars (e.g. request → _request)
    • Convert string matches to raw regex where appropriate
    tests/fastapi/test_context.py
    tests/experimental/pydantic/test_basic.py
    tests/http/clients/sanic.py
    tests/litestar/test_context.py
    tests/fastapi/test_router.py
    ...
    Apply automated formatting via ruff-format
    • Reformat code and tests to satisfy updated ruff rules
    (multiple source and test files across the repo)

    Tips and commands

    Interacting with Sourcery

    • Trigger a new review: Comment @sourcery-ai review on the pull request.
    • Continue discussions: Reply directly to Sourcery's review comments.
    • Generate a GitHub issue from a review comment: Ask Sourcery to create an
      issue from a review comment by replying to it. You can also reply to a
      review comment with @sourcery-ai issue to create an issue from it.
    • Generate a pull request title: Write @sourcery-ai anywhere in the pull
      request title to generate a title at any time. You can also comment
      @sourcery-ai title on the pull request to (re-)generate the title at any time.
    • Generate a pull request summary: Write @sourcery-ai summary anywhere in
      the pull request body to generate a PR summary at any time exactly where you
      want it. You can also comment @sourcery-ai summary on the pull request to
      (re-)generate the summary at any time.
    • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
      request to (re-)generate the reviewer's guide at any time.
    • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
      pull request to resolve all Sourcery comments. Useful if you've already
      addressed all the comments and don't want to see them anymore.
    • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
      request to dismiss all existing Sourcery reviews. Especially useful if you
      want to start fresh with a new review - don't forget to comment
      @sourcery-ai review to trigger a new review!

    Customizing Your Experience

    Access your dashboard to:

    • Enable or disable review features such as the Sourcery-generated pull request
      summary, the reviewer's guide, and others.
    • Change the review language.
    • Add, remove or edit custom review instructions.
    • Adjust other review settings.

    Getting Help

    Copy link
    Contributor

    @sourcery-ai sourcery-ai bot left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Hey there - I've reviewed your changes and they look great!


    Sourcery is free for open source - if you like our reviews please consider sharing them ✨
    Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

    # is added in the constructor or not. It is not used to change
    # any behaviour at the moment.
    init: Literal[True, False, None] = None,
    init: Literal[True, False] | None = None,
    Copy link
    Member Author

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    should this be bool | None? 🤔

    @botberry
    Copy link
    Member

    Hi, thanks for contributing to Strawberry 🍓!

    We noticed that this PR is missing a RELEASE.md file. We use that to automatically do releases here on GitHub and, most importantly, to PyPI!

    So as soon as this PR is merged, a release will be made 🚀.

    Here's an example of RELEASE.md:

    Release type: patch
    
    Description of the changes, ideally with some examples, if adding a new feature.

    Release type can be one of patch, minor or major. We use semver, so make sure to pick the appropriate type. If in doubt feel free to ask :)

    Here's the tweet text:

    🆕 Release (next) is out! Thanks to @_bellini666 for the PR 👏
    
    Get it here 👉 https://strawberry.rocks/release/(next)
    

    @botberry
    Copy link
    Member

    Apollo Federation Subgraph Compatibility Results

    Federation 1 Support Federation 2 Support
    _service🟢
    @key (single)🟢
    @key (multi)🟢
    @key (composite)🟢
    repeatable @key🟢
    @requires🟢
    @provides🟢
    federated tracing🔲
    @link🟢
    @shareable🟢
    @tag🟢
    @override🟢
    @inaccessible🟢
    @composeDirective🟢
    @interfaceObject🟢

    Learn more:

    Copy link
    Contributor

    @greptile-apps greptile-apps bot left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Greptile Overview

    Summary

    This PR fixes import sorting issues introduced in PR #4032 by updating the ruff linter configuration and applying the corrected import order across all affected files.

    Key Changes:

    • Updated ruff from v0.12.10 to v0.14.1 in .pre-commit-config.yaml
    • Added integration packages (fastapi, django, pydantic, litestar, aiohttp, channels, sanic, chalice, quart) to known-third-party in pyproject.toml
    • Re-sorted imports in 49 files to follow the correct order: standard library → third-party (integrations) → first-party (strawberry)

    Impact:
    The previous PR incorrectly treated integration packages as first-party, placing them after strawberry imports. This fix ensures proper import grouping, which is important for:

    • Code readability and maintainability
    • Consistent style across the codebase
    • Avoiding future import-related issues

    All changes are purely cosmetic (import reordering and whitespace) with no functional modifications.

    Confidence Score: 5/5

    • This PR is completely safe to merge - it only reorders imports and updates tooling versions
    • This PR receives the highest confidence score because: (1) All changes are purely cosmetic - only import statement ordering and blank lines were modified, (2) No logical code changes were made, (3) The Python syntax validation passed for all modified files, (4) The changes fix a legitimate issue where integration packages were incorrectly sorted, (5) The ruff version update and configuration changes are straightforward and well-understood, (6) The changes align with Python PEP 8 import ordering conventions
    • No files require special attention - all changes are automated import reordering

    Important Files Changed

    File Analysis

    Filename Score Overview
    .pre-commit-config.yaml 5/5 Updated ruff from v0.12.10 to v0.14.1 and blacken-docs from 1.19.1 to 1.20.0 - version bumps only
    pyproject.toml 5/5 Updated ruff version constraint and added integration packages to known-third-party for correct import sorting
    strawberry/fastapi/router.py 5/5 Reordered imports: fastapi imports now correctly appear before strawberry imports
    strawberry/litestar/controller.py 5/5 Reordered imports: litestar and msgspec now correctly grouped as third-party before strawberry
    strawberry/aiohttp/views.py 5/5 Reordered imports: aiohttp now correctly appears before strawberry imports

    Sequence Diagram

    sequenceDiagram
        participant Dev as Developer
        participant Git as Git Commit
        participant PreCommit as Pre-commit Hooks
        participant Ruff as Ruff v0.14.1
        participant Config as pyproject.toml
    
        Dev->>Git: git commit
        Git->>PreCommit: Trigger pre-commit hooks
        PreCommit->>Ruff: Run ruff-format
        Ruff->>Config: Read [tool.ruff.lint.isort] config
        Config-->>Ruff: known-third-party includes:<br/>fastapi, django, litestar,<br/>aiohttp, channels, sanic, etc.
        Ruff->>Ruff: Sort imports:<br/>1. Standard library<br/>2. Third-party (fastapi, django, etc.)<br/>3. First-party (strawberry)
        Ruff-->>PreCommit: Import order corrected
        PreCommit->>Ruff: Run ruff linter
        Ruff-->>PreCommit: All checks passed
        PreCommit-->>Git: All hooks passed
        Git-->>Dev: Commit successful
    
    Loading

    48 files reviewed, no comments

    Edit Code Review Agent Settings | Greptile

    @codspeed-hq
    Copy link

    codspeed-hq bot commented Oct 22, 2025

    CodSpeed Performance Report

    Merging #4033 will not alter performance

    Comparing update-pre-commit (62e19ac) with main (938f940)

    Summary

    ✅ 26 untouched

    @patrick91 patrick91 merged commit 80503ff into main Oct 23, 2025
    81 of 82 checks passed
    @patrick91 patrick91 deleted the update-pre-commit branch October 23, 2025 07:53
    @codecov
    Copy link

    codecov bot commented Oct 23, 2025

    Codecov Report

    ✅ All modified and coverable lines are covered by tests.
    ✅ Project coverage is 94.37%. Comparing base (938f940) to head (62e19ac).
    ⚠️ Report is 1 commits behind head on main.

    Additional details and impacted files
    @@           Coverage Diff           @@
    ##             main    #4033   +/-   ##
    =======================================
      Coverage   94.37%   94.37%           
    =======================================
      Files         533      533           
      Lines       34774    34774           
      Branches     1829     1829           
    =======================================
      Hits        32819    32819           
      Misses       1659     1659           
      Partials      296      296           
    🚀 New features to boost your workflow:
    • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
    • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Labels

    None yet

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    4 participants