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

[BUG] Utilising TestAsyncClient with await causes a mypy error #1361

Open
anorthall opened this issue Dec 15, 2024 · 0 comments
Open

[BUG] Utilising TestAsyncClient with await causes a mypy error #1361

anorthall opened this issue Dec 15, 2024 · 0 comments

Comments

@anorthall
Copy link

Running the following minimal example:

from ninja.testing import TestAsyncClient
from core.api import api

async def test_async_client_mypy() -> None:
    client = TestAsyncClient(api)
    response = await client.get("/")

Produces the following mypy error:

error: "NinjaResponse" has no attribute "__await__"  [attr-defined]

Am I doing something wrong here - misunderstanding how this is supposed to work - or is this a real bug? Clearly the TestAsyncClient returns a coroutine when being utilised on an Async view, and also clearly no such __await__ method is defined. I would think that either:

  • Documentation needs to be improve to indicate proper usage, or
  • Stubs need to be improved to silence mypy

To be clear, there is no actual functional problem here. The test client works fine in the example above. It is purely that an error is thrown by mypy.

Relevant parts of mypy config:

[mypy]
strict = True
plugins = pydantic.mypy, mypy_django_plugin.main

[mypy.plugins.django-stubs]
django_settings_module = "config.django.settings.local"

[pydantic-mypy]
init_forbid_extra = True
init_typed = True
warn_required_dynamic_aliases = True

Versions

  • python: 3.12.8
  • django: 5.1.4
  • django-ninja: 1.3.0
  • pydantic: 2.10.3
  • mypy: 1.13.0
  • django-stubs: 5.1.1
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

No branches or pull requests

1 participant