sbdchd / django-types

:doughnut: Type stubs for Django
MIT License
187 stars 62 forks source link

User.objects is UserManager[Self] #177

Open bobthemighty opened 1 year ago

bobthemighty commented 1 year ago

This commit fixes an issue with extending the User class.

Previously, MySpecialUser.objects would return a UserManager[User]. This commit updates the objects field to parameterise over Self, so that MySpecialUser.objects returns a UserManager[MySpecialUser].

sbdchd commented 1 year ago

Looks good!

Linter is a little angry:

18
All done! ✨ 🍰 ✨
[19](https://github.com/sbdchd/django-types/actions/runs/5488440137/jobs/10001296563?pr=177#step:8:20)
3 files reformatted, 699 files left unchanged.
[20](https://github.com/sbdchd/django-types/actions/runs/5488440137/jobs/10001296563?pr=177#step:8:21)
+ ./.venv/bin/isort tests typings
[21](https://github.com/sbdchd/django-types/actions/runs/5488440137/jobs/10001296563?pr=177#step:8:22)
+ ./.venv/bin/mypy tests typings
[22](https://github.com/sbdchd/django-types/actions/runs/5488440137/jobs/10001296563?pr=177#step:8:23)
tests/trout/models.py:1050:1: error: Access to generic instance variables via class is ambiguous  [misc]
[23](https://github.com/sbdchd/django-types/actions/runs/5488440137/jobs/10001296563?pr=177#step:8:24)
Found 1 error in 1 file (checked 702 source files)
[24](https://github.com/sbdchd/django-types/actions/runs/5488440137/jobs/10001296563?pr=177#step:8:25)
Error: Process completed with exit code 1.
bobthemighty commented 1 year ago

Locally ./s/lint now runs clean, so I'm unsure how to reproduce the build failure I have here. Any clue?

sbdchd commented 1 year ago

Hmm seems mypy is mad, maybe # type: ignore[misc] for now?

hamdanal commented 1 year ago

It appears that #181 fixes User.objects type annotation. @bobthemighty would you like to change the PR to only include the test? Otherwise this PR can be closed.