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

(imp) support type[strawberry.UNSET] #3765

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

alexey-pelykh
Copy link
Contributor

@alexey-pelykh alexey-pelykh commented Feb 2, 2025

Description

Support for type[strawberry.UNSET] in addition to strawberry.types.unset.UnsetType

Types of Changes

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

Issues Fixed or Closed by This PR

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

Summary by Sourcery

Add support for type[strawberry.UNSET] in annotations, expanding the ways to specify optional fields.

New Features:

  • Allow using type[strawberry.UNSET] to indicate optional fields in type annotations.

Tests:

  • Added tests to verify the behavior of optional fields with type[strawberry.UNSET].

Copy link
Contributor

sourcery-ai bot commented Feb 2, 2025

Reviewer's Guide by Sourcery

This pull request introduces support for type[strawberry.UNSET] in addition to strawberry.types.unset.UnsetType. This change allows developers to use type[strawberry.UNSET] when defining optional input types, providing more flexibility when defining input types.

Class diagram showing Point2D input type changes

classDiagram
    class Point2D {
        +float x
        +float y
        +Optional[str] | type[strawberry.UNSET] label
    }
    note for Point2D "Updated to support type[strawberry.UNSET]"
Loading

File-Level Changes

Change Details Files
Added support for type[strawberry.UNSET] when resolving optionals.
  • Modified the filter in create_optional to include x != type[UNSET].
strawberry/annotation.py
Added a test case for type[strawberry.UNSET].
  • Added test_optional_with_type_of_unset to verify that type[strawberry.UNSET] is correctly handled.
tests/types/resolving/test_optionals.py
Updated documentation to include type[strawberry.UNSET] as a valid type for optionals.
  • Updated the example to include `Optional[str]
type[strawberry.UNSET]`.
Added release notes.
  • Added a release note indicating the new feature.
tests/RELEASE.md

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!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

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 @alexey-pelykh - 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.

@botberry
Copy link
Member

botberry commented Feb 2, 2025

Thanks for adding the RELEASE.md file!

Here's a preview of the changelog:


Support for type[strawberry.UNSET] in addition to strawberry.types.unset.UnsetType for annotations.

Here's the tweet text:

🆕 Release (next) is out! Thanks to Alexey Pelykh for the PR 👏

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

@botberry
Copy link
Member

botberry commented Feb 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 Alexey Pelykh for the PR 👏

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

docs/types/input-types.md Outdated Show resolved Hide resolved
RELEASE.md Outdated Show resolved Hide resolved
Copy link

codecov bot commented Feb 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.27%. Comparing base (7ba5928) to head (07429d6).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3765   +/-   ##
=======================================
  Coverage   97.27%   97.27%           
=======================================
  Files         504      504           
  Lines       33480    33487    +7     
  Branches     5502     5502           
=======================================
+ Hits        32566    32573    +7     
  Misses        703      703           
  Partials      211      211           

Copy link

codspeed-hq bot commented Feb 3, 2025

CodSpeed Performance Report

Merging #3765 will not alter performance

Comparing alexey-pelykh:imp/type-unset (07429d6) with main (407b14f)

Summary

✅ 21 untouched benchmarks

Copy link
Member

@bellini666 bellini666 left a comment

Choose a reason for hiding this comment

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

LGTM

Asking review from @patrick91 as well, just to get a second opinion

@bellini666 bellini666 requested a review from patrick91 February 3, 2025 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Explore if we can improve the typing for UNSET Add support for implicit UNSET as a type annotation
3 participants