Skip to content
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

chore(ruff): Enable and fix all ruff rules that we can #3742

Merged
merged 8 commits into from
Jan 4, 2025
Merged

Conversation

bellini666
Copy link
Member

@bellini666 bellini666 commented Dec 26, 2024

I went through all ruff rules we were ignoring and enabled all that made sense.

Some have legit use cases in some places, so I changed to an inline "# noqa " instead of having to disable those for the whole file. Some still made sense to be ignored on tests.

Summary by Sourcery

Enable more Ruff rules and fix existing violations.

@bellini666 bellini666 self-assigned this Dec 26, 2024
Copy link
Contributor

sourcery-ai bot commented Dec 26, 2024

Reviewer's Guide by Sourcery

This pull request enables and fixes all applicable ruff rules, improving code style and maintainability. Some rules are ignored inline with "# noqa " where necessary, particularly in tests, to accommodate specific use cases.

Class diagram showing key changes to error handling patterns

classDiagram
    class BaseException {
        +message: str
        +raise_from(cause: Exception)
    }
    class CustomError {
        +message: str
        +__init__(message: str)
    }
    class ErrorWithPayload {
        +payload: dict
        +__init__(payload: dict)
    }

    BaseException <|-- CustomError
    BaseException <|-- ErrorWithPayload

    note for CustomError "Changed to use raise from pattern"
    note for ErrorWithPayload "Changed to use None default for payload"
Loading

File-Level Changes

Change Details Files
Enabled more ruff rules and removed some ignores
  • Enabled ruff rules that were previously ignored
  • Removed some unnecessary ignore rules
  • Replaced file-level ignore rules with inline ignore comments using "# noqa " in specific cases
  • Kept some ignore rules for tests
pyproject.toml
Refactored code to comply with newly enabled ruff rules
  • Updated code to adhere to stricter linting rules
strawberry/extensions/field_extension.py
strawberry/extensions/query_depth_limiter.py
strawberry/annotation.py
tests/types/test_lazy_types.py
strawberry/extensions/context.py
strawberry/schema/schema_converter.py
strawberry/types/fields/resolver.py
strawberry/types/base.py
strawberry/cli/commands/codegen.py
strawberry/extensions/tracing/opentelemetry.py
strawberry/schema/execute.py
strawberry/ext/mypy_plugin.py
strawberry/types/field.py
tests/relay/test_types.py
strawberry/codegen/query_codegen.py
tests/schema/test_resolvers.py
tests/schema/test_union.py
strawberry/cli/__init__.py
strawberry/experimental/pydantic/utils.py
strawberry/schema/schema.py
strawberry/litestar/controller.py
strawberry/schema_codegen/__init__.py
tests/schema/extensions/test_query_depth_limiter.py
tests/schema/extensions/schema_extensions/test_extensions.py
tests/types/cross_module_resolvers/c_mod.py
strawberry/experimental/pydantic/conversion.py
strawberry/schema/name_converter.py
tests/schema/extensions/test_field_extensions.py
strawberry/asgi/__init__.py
strawberry/experimental/pydantic/_compat.py
strawberry/schema/subscribe.py
strawberry/schema/types/base_scalars.py
strawberry/utils/graphql_lexer.py
tests/channels/test_layers.py
tests/experimental/pydantic/test_basic.py
tests/http/clients/aiohttp.py
tests/plugins/strawberry_exceptions.py
tests/test_dataloaders.py
strawberry/aiohttp/test/client.py
strawberry/codegen/plugins/python.py
tests/http/clients/fastapi.py
tests/http/clients/quart.py
tests/http/clients/sanic.py
tests/types/cross_module_resolvers/test_cross_module_resolvers.py
strawberry/aiohttp/views.py
strawberry/channels/handlers/ws_handler.py
strawberry/cli/commands/server.py
strawberry/codemods/update_imports.py
strawberry/exceptions/__init__.py
strawberry/federation/schema.py
strawberry/http/async_base_view.py
strawberry/types/auto.py
tests/experimental/pydantic/test_conversion.py
tests/fields/test_field_defaults.py
tests/fields/test_field_exceptions.py
tests/fields/test_resolvers.py
tests/schema/test_basic.py
tests/schema/test_one_of.py
tests/test_printer/test_basic.py
strawberry/cli/commands/upgrade/_run_codemod.py
strawberry/django/views.py
strawberry/fastapi/router.py
strawberry/relay/utils.py
.github/release-check-action/release.py
strawberry/channels/testing.py
strawberry/dataloader.py
strawberry/django/__init__.py
strawberry/experimental/pydantic/object_type.py
strawberry/flask/views.py
strawberry/http/ides.py
strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py
strawberry/types/arguments.py
tests/federation/printer/test_additional_directives.py
tests/federation/printer/test_compose_directive.py
tests/http/conftest.py
tests/http/test_upload.py
tests/python_312/test_generics_schema.py
tests/python_312/test_python_generics.py
tests/schema/extensions/schema_extensions/conftest.py
tests/schema/test_execution.py
tests/schema/test_permission.py
tests/schema/test_subscription.py
tests/schema/types/test_date.py
tests/schema/types/test_datetime.py
tests/schema/types/test_time.py
tests/typecheckers/utils/mypy.py
tests/types/resolving/test_unions.py
tests/websockets/conftest.py
tests/websockets/test_graphql_ws.py
tests/websockets/views.py
strawberry/schema/base.py

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.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a 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. You can also use
    this command to specify where the summary should be inserted.

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 @bellini666 - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

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.

tests/http/clients/aiohttp.py Show resolved Hide resolved
tests/http/clients/asgi.py Show resolved Hide resolved
tests/http/clients/async_django.py Show resolved Hide resolved
tests/http/clients/async_flask.py Show resolved Hide resolved
tests/http/clients/chalice.py Show resolved Hide resolved
strawberry/cli/commands/codegen.py Show resolved Hide resolved
strawberry/codegen/query_codegen.py Outdated Show resolved Hide resolved
strawberry/types/auto.py Show resolved Hide resolved
tests/fields/test_resolvers.py Show resolved Hide resolved
tests/test_printer/test_basic.py Show resolved Hide resolved
@botberry
Copy link
Member

botberry commented Dec 26, 2024

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:

@botberry
Copy link
Member

botberry commented Dec 26, 2024

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)

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Copy link

codecov bot commented Dec 26, 2024

Codecov Report

Attention: Patch coverage is 91.69139% with 28 lines in your changes missing coverage. Please review.

Project coverage is 97.28%. Comparing base (15044cd) to head (28a6ecb).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3742      +/-   ##
==========================================
- Coverage   97.32%   97.28%   -0.04%     
==========================================
  Files         501      502       +1     
  Lines       33386    33375      -11     
  Branches     5478     5477       -1     
==========================================
- Hits        32493    32469      -24     
- Misses        685      697      +12     
- Partials      208      209       +1     

Copy link

codspeed-hq bot commented Dec 26, 2024

CodSpeed Performance Report

Merging #3742 will not alter performance

Comparing ruff_rules (28a6ecb) with main (15044cd)

Summary

✅ 21 untouched benchmarks

.github/release-check-action/release.py Outdated Show resolved Hide resolved
strawberry/aiohttp/test/client.py Outdated Show resolved Hide resolved
strawberry/annotation.py Outdated Show resolved Hide resolved
strawberry/cli/commands/codegen.py Outdated Show resolved Hide resolved
strawberry/django/views.py Outdated Show resolved Hide resolved
strawberry/relay/utils.py Outdated Show resolved Hide resolved
strawberry/cli/commands/server.py Outdated Show resolved Hide resolved
strawberry/cli/utils/__init__.py Outdated Show resolved Hide resolved
strawberry/chalice/views.py Outdated Show resolved Hide resolved
Copy link
Member

@erikwrede erikwrede left a comment

Choose a reason for hiding this comment

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

reviewed everything but tests, some comments are very opinionated

strawberry/chalice/views.py Outdated Show resolved Hide resolved
strawberry/extensions/context.py Outdated Show resolved Hide resolved
@@ -88,7 +87,6 @@ def get_type_by_name(
raise NotImplementedError

@abstractmethod
@lru_cache
Copy link
Member

Choose a reason for hiding this comment

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

just flagging this to come back & check the children later

strawberry/schema/schema.py Outdated Show resolved Hide resolved
strawberry/schema/types/base_scalars.py Outdated Show resolved Hide resolved
strawberry/schema/types/base_scalars.py Outdated Show resolved Hide resolved
tests/experimental/pydantic/test_conversion.py Outdated Show resolved Hide resolved
tests/fields/test_field_defaults.py Outdated Show resolved Hide resolved
@bellini666
Copy link
Member Author

@patrick91 @erikwrede thank you for the careful review :) (the PR is large lol)

I reverted the changes for the rules that we don't want in the codebase and added them to the ignore list.

Let me know if there's anything else you want me to revert here

Copy link
Member

@erikwrede erikwrede left a comment

Choose a reason for hiding this comment

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

lgtm now :) @patrick91 what do you think?

@bellini666 bellini666 merged commit 6bc7332 into main Jan 4, 2025
91 of 94 checks passed
@bellini666 bellini666 deleted the ruff_rules branch January 4, 2025 11:08
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