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

Alias argument to QuerySet.using() typed as _SpecialForm #958

Closed
ljodal opened this issue May 15, 2022 · 0 comments · Fixed by #1028
Closed

Alias argument to QuerySet.using() typed as _SpecialForm #958

ljodal opened this issue May 15, 2022 · 0 comments · Fixed by #1028
Labels
bug Something isn't working

Comments

@ljodal
Copy link
Contributor

ljodal commented May 15, 2022

Bug report

What's wrong

For some custom managers in our codebase we get an incorrect typing error for calls to .using():

error: Argument 1 to "using" of "SomeManager" has incompatible type "str"; expected "_SpecialForm"  [arg-type]

Stepping through the plugin this appears to stem from this call to helpers.copy_method_to_another_class. That calls bind_or_anaylyze_type for each argument, which again ends up calling api.lookup_fully_qualified_or_none("django.db.models.query.Optional"). This is where the _SpecialCase comes into play, because the type of the alias parameter is an instance of UnboundType up to this point.

Has anyone else seen this? I've been unable to create an isolated reproducer and I'm not familiar enough with mypy to understand what's really going on here. Would love to get this fixed though, as it's causing us use a lot of # type: ignore comments! I'll keep digging, but would love some help to get this fixed.

How is that should be

The type signature should be kept as def (self: _QS, alias: Optional[str]) -> _QS.

System information

  • OS: macOS 12.3.1 and Ubuntu 20.04
  • python version: 3.9.9 an 3.10.2
  • django version: 3.2.13
  • mypy version: 0.950
  • django-stubs version: latest master (e221f0e0533c98417ed726cba764b5f6282442f8)
  • django-stubs-ext version: latest master (e221f0e0533c98417ed726cba764b5f6282442f8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

1 participant