-
-
Notifications
You must be signed in to change notification settings - Fork 578
Description
Describe the Bug
Using @strawberry.field
as a decorator is nifty, but it seems like its type annotations only work great if it's called without arguments. If it's called like @strawberry.field(name="whatever")
, mypy considers the decorator untyped and thus gives 'untyped decorator makes function .. untyped' errors in strict mode.
For instance, adjust test_all_field_usage
in test_fields.yml
to use strict mode:
modified tests/mypy/test_fields.yml
@@ -40,6 +40,8 @@
reveal_type(Example.d)
reveal_type(Example.e)
reveal_type(Example.f_resolver)
+ mypy_config: |
+ strict = true
out: |
main:22: note: Revealed type is "builtins.str"
main:23: note: Revealed type is "builtins.str"
There's a whole much of output, but the key lines are towards the end (just before the real Revealed type
output):
E main:14: error: Untyped decorator makes function "e" untyped [misc] (diff)
...
E main:18: error: Untyped decorator makes function "f_resolver" untyped [misc] (diff)
...
This is easily squashed by # type: ignore[misc]
annotations, but it'd be neat if we could avoid them 😄
If the test is additionally edited to remove the arguments to field
, there's no complains about untyped decorators:
modified tests/mypy/test_fields.yml
@@ -26,11 +26,11 @@
c: str = strawberry.field(name="c", resolver=some_resolver)
d: str = strawberry.field(resolver=some_resolver)
- @strawberry.field(description="ABC")
+ @strawberry.field
def e(self, info: Info) -> str:
return ""
- @strawberry.field(name="f")
+ @strawberry.field
def f_resolver(self, info) -> str:
return ""
System Information
- Operating system: macOS
- Strawberry version (if applicable): main (a382872)
Additional Context
As always, thanks for strawberry! 🍓
Metadata
Metadata
Assignees
Labels
Type
Projects
Status