strawberry icon indicating copy to clipboard operation
strawberry copied to clipboard

Use dataclasses.MISSING for default value for default and default_factory

Open patrick91 opened this issue 3 years ago • 2 comments
trafficstars

This PR changes the default for default and default_factory to dataclasses.MISSING to allow using UNSET as default when doing something like this:

@strawberry.input
class FilterInput:
    in_: Optional[str] = strawberry.field(name="in", default=strawberry.UNSET)

I don't like the double checks we added for UNSERT and dataclasses.MISSING, maybe we can add a util function, or see if we can remove some of them.

I wanted to update the mypy plugin too, but it seem to trigger an unrelated error, so I'll avoid doing that for now :)

patrick91 avatar Aug 25 '22 18:08 patrick91

Codecov Report

Merging #2128 (49a92af) into main (1bb0328) will increase coverage by 0.01%. The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2128      +/-   ##
==========================================
+ Coverage   98.19%   98.21%   +0.01%     
==========================================
  Files         162      162              
  Lines        6494     6496       +2     
  Branches     1447     1449       +2     
==========================================
+ Hits         6377     6380       +3     
+ Misses         58       57       -1     
  Partials       59       59              

codecov[bot] avatar Aug 25 '22 18:08 codecov[bot]

Thanks for adding the RELEASE.md file!

Here's a preview of the changelog:


This release fixes an issue that prevented using strawberry.field with UNSET as the default value.


Here's the preview release card for twitter:

Here's the tweet text:

🆕 Release (next) is out! Thanks to @patrick91 for the PR 👏

Get it here 👉 https://github.com/strawberry-graphql/strawberry/releases/tag/(next)

botberry avatar Aug 25 '22 18:08 botberry