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

Type internal test clients stricter #3745

Merged
merged 2 commits into from
Jan 3, 2025

Conversation

DoctorJohn
Copy link
Member

@DoctorJohn DoctorJohn commented Jan 2, 2025

Description

This PR improves the typing of our internal HTTP test clients.

The motivation behind this is to see what parts of them could be re/used for our public test clients and to make pylance and me much happier when I work in vscode lol

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Documentation

Summary by Sourcery

Enhancements:

  • Add generic type parameters to internal HTTP test clients to improve type checking.

Copy link
Contributor

sourcery-ai bot commented Jan 2, 2025

Reviewer's Guide by Sourcery

This PR enhances type annotations across various internal HTTP test clients, improving their compatibility with public test clients and enhancing type checking during development.

Class diagram showing BaseGraphQLWSHandler type changes

classDiagram
    class BaseGraphQLWSHandler~Context, RootValue~ {
        -view: AsyncBaseHTTPView
        +__init__(view)
    }
    note for BaseGraphQLWSHandler "Removed explicit context and root_value attributes
Now handled through generic type parameters"
Loading

File-Level Changes

Change Details Files
Added stricter type annotations to HTTP test client classes and methods.
  • Generic type parameters were added to various classes like DebuggableGraphQLHTTPConsumer, GraphQLView, GraphQLRouter, AsyncGraphQLView, DebuggableGraphQLTransportWSHandler, DebuggableGraphQLWSHandler, and OnWSConnectMixin to enforce stricter type constraints.
  • Type hints were added or refined for method parameters and return values, such as specifying dict[str, object] for variables, str for query parameters, and explicit types for request and response objects.
  • Type hints for context objects were updated to dict[str, object] in several methods.
  • The query parameter in _graphql_request methods was changed from optional to required.
  • Type hints were updated in WebSocket client methods, such as send_json and receive_json.
  • Changes in create_multipart_request_body now return a dictionary of header pairs, improving type handling.
  • Updated type hints in request methods to handle headers and body data more accurately.
tests/http/clients/channels.py
tests/http/clients/django.py
tests/http/clients/litestar.py
tests/http/clients/fastapi.py
tests/http/clients/asgi.py
tests/websockets/views.py
tests/http/clients/async_django.py
tests/http/clients/base.py
tests/http/clients/aiohttp.py
tests/http/clients/chalice.py
tests/http/clients/flask.py
tests/http/clients/async_flask.py
tests/http/clients/quart.py
strawberry/subscriptions/protocols/graphql_ws/handlers.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 @DoctorJohn - 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/fastapi.py Show resolved Hide resolved
@botberry
Copy link
Member

botberry commented Jan 2, 2025

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 @NucleonJohn for the PR 👏

Get it here 👉 https://strawberry.rocks/release/(next)

Copy link

codspeed-hq bot commented Jan 2, 2025

CodSpeed Performance Report

Merging #3745 will not alter performance

Comparing type-internal-test-clients-stricter (5dce666) with main (e78f8c6)

Summary

✅ 21 untouched benchmarks

Copy link

codecov bot commented Jan 2, 2025

Codecov Report

Attention: Patch coverage is 95.23810% with 3 lines in your changes missing coverage. Please review.

Project coverage is 97.32%. Comparing base (e78f8c6) to head (5dce666).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3745      +/-   ##
==========================================
+ Coverage   97.27%   97.32%   +0.04%     
==========================================
  Files         501      501              
  Lines       33408    33386      -22     
  Branches     5480     5478       -2     
==========================================
- Hits        32499    32493       -6     
+ Misses        701      685      -16     
  Partials      208      208              

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.

minor thoughts, rest LGTM

tests/http/clients/asgi.py Outdated Show resolved Hide resolved
tests/http/clients/async_flask.py Show resolved Hide resolved
tests/http/clients/fastapi.py Outdated Show resolved Hide resolved
@DoctorJohn DoctorJohn force-pushed the type-internal-test-clients-stricter branch from 77af746 to 5dce666 Compare January 3, 2025 17:04
@DoctorJohn DoctorJohn merged commit 15044cd into main Jan 3, 2025
91 of 93 checks passed
@DoctorJohn DoctorJohn deleted the type-internal-test-clients-stricter branch January 3, 2025 18:10
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.

5 participants