strawberry-graphql / strawberry

A GraphQL library for Python that leverages type annotations 🍓
https://strawberry.rocks
MIT License
3.92k stars 516 forks source link

mypy error: Unexpected keyword argument "ok" for "EditUserResponse" #1999

Open eloff opened 2 years ago

eloff commented 2 years ago
from strawberry_django_plus import gql

@gql.type
class EditUserResponse:
    ok: bool
    reason: Optional[str] = None

...

return EditUserResponse(ok=True)

Produces the error when I run mypy.

My pyproject.toml looks like:

[tool.mypy]
disallow_untyped_defs = false
ignore_missing_imports = true
plugins = [
    "strawberry.ext.mypy_plugin",
    "mypy_django_plugin.main",
]

[tool.django-stubs]
django_settings_module = "config.settings.test"

pythonVersion = "3.10"
pythonPlatform = "Linux"

Strawberry version:

       "strawberry-django-plus": {
            "hashes": [
                "sha256:9c6be105942c2405a595cb9a1163d69c501301333054da0c08a377bd3633a92e",
                "sha256:c79c474ea71f61b78f8639eb8b68c698927cbe7b1fa05aabdc6b97be9223364a"
            ],
            "index": "pypi",
            "version": "==1.14.1"
        },
        "strawberry-graphql": {
            "hashes": [
                "sha256:93cf617fb830f97ef5fad67655de5e6f9079c37271c696efbdb1fc299a3ff0f0",
                "sha256:cedb10b4981b183b318187c78d9b666fd44464fb63fafcbfe55c624372bb33dd"
            ],
            "index": "pypi",
            "version": "==0.114.0"
        },
        "strawberry-graphql-django": {
            "hashes": [
                "sha256:d66dd816211b5e4a60920a9e0697c1df63d8e14edf02ab04e1c1b696d19eda33",
                "sha256:f2c55da70d02cb67ee225995798a4b5f26b802228a4fa8fb931eb55e50c775dd"
            ],
            "markers": "python_version >= '3.7' and python_full_version < '4.0.0'",
            "version": "==0.3.1"
        },

Upvote & Fund

Fund with Polar

patrick91 commented 2 years ago

hi eloff! I think this is because strawberry_django_plus doesn't have a mypy plugin yet, maybe we should add one, or add support for it in our plugin 🤔

@bellini666 what do you think?

eloff commented 2 years ago

@patrick91 gql.type is just strawberry.type, shouldn't it work normally with the strawberry mypy plugin (enabled from my config I shared)?

patrick91 commented 2 years ago

@patrick91 gql.type is just strawberry.type, shouldn't it work normally with the strawberry mypy plugin (enabled from my config I shared)?

I'm not 100% sure, the plugin uses the import name to work, not sure if it is able to follow the import. Also it looks like strawberry django plus is missing the py.typed file, that might be another issue :)

bellini666 commented 2 years ago

hi eloff! I think this is because strawberry_django_plus doesn't have a mypy plugin yet, maybe we should add one, or add support for it in our plugin thinking

@bellini666 what do you think?

I like the idea! I don't know much of mypy plugins (don't actually use mypy, just pyright), but I think it would be nice to add support for it.

I'm not 100% sure, the plugin uses the import name to work, not sure if it is able to follow the import. Also it looks like strawberry django plus is missing the py.typed file, that might be another issue :)

I'm not really sure also how that works for mypy. But if adding a py.typed file helps, I can add one there :)