Commit Graph

727 Commits

Author SHA1 Message Date
Nikita Sobolev
d5e45db79b Better linting config (#664)
* Better linting config

* Applies isort on django-stubs, only style changes

* Fixes black and isort compat
2021-07-04 16:16:43 +03:00
Nikita Sobolev
552f2ffc0c Adds more rules to mypy config, related #662 (#663)
* Adds more rules to mypy config, related #662

* Removes plugin.ini for mypy settings

* Fixes build
2021-07-04 15:41:51 +03:00
horpto
d9c63f5e71 fix CursorWrapper iter method (#628) 2021-07-04 15:11:21 +03:00
Michael Aquilina
008dcdbcb6 chore: remove excess # type: ignore comments in _ValuesQuerySet (#662) 2021-07-04 14:53:28 +03:00
Michael Aquilina
5c3ce171b2 Add more method signatures for _ValuesQuerySet (#661) 2021-07-03 20:12:05 +03:00
Michael Aquilina
13c620f572 chore: remove unused class stubs from query.pyi (#660) 2021-07-03 16:14:16 +03:00
Michael Aquilina
ded66f6937 Add distinct, order_by and all method signatures for _ValuesQuerySet (#657) 2021-07-03 16:00:58 +03:00
David Szotten
739b1711a9 Use Sequence instead of List for path param (#659)
Unlike `List`, which is invariant, `Sequence` is covariant, which lets
`path` accept lists of subsets of the `Union` as well.

I believe this is safe, as django doesn't mutate this input. I found
[this
comment](https://github.com/python/mypy/issues/3351#issuecomment-300447832)
helpful
2021-07-03 13:46:29 +03:00
darius-blink
cf6952c9df Fix type of MigrationLoader.applied_migrations (#656)
Co-authored-by: Darius Marian <marian.darius98@gmail.com>
2021-06-30 12:23:48 +03:00
Seth Yastrov
0c3252fb97 Check whether reported issues actually fails currently (#653) 2021-06-28 13:23:20 +03:00
Seth Yastrov
f9317c7679 Rename ValuesQuerySet -> _ValuesQuerySet and remove _BaseQuerySet. Ma… (#654)
* Rename ValuesQuerySet -> _ValuesQuerySet and remove _BaseQuerySet. Make a public alias called ValuesQuerySet in django_stubs_ext.

* Update tests
2021-06-28 13:23:00 +03:00
Seth Yastrov
29e971ed9d Allow setting AutoFields to None (#634) 2021-06-28 03:23:54 +03:00
Daniel Hahler
a00563cfa4 [WIP/RFC] Revisit patching of mypy builtins (reveal_{type,locals}) (#615)
* Revisit patching of mypy builtins (reveal_{type,locals})

Fixes https://github.com/typeddjango/django-stubs/issues/609
Reverts ee58b18f15

* Create test_patching.yml

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2021-06-25 16:56:21 +03:00
sobolevn
159a0e4790 Adds docs for how Field access works 2021-06-23 13:44:06 +03:00
Nikita Sobolev
eb702384a8 Improves edit.py and its forms (#648)
* Improves edit.py and its forms

* Adds tests
2021-06-16 11:25:57 +03:00
Chris Beaven
acfe0ce820 Patch detail and list generic view base classes (#642)
Similar to the already patched `FormMixin`, the detail and list generic view classes are also missing __class_getitem__ and choke when you try to use their generics.
2021-06-16 10:32:47 +03:00
Patrick Gingras
f182b39c91 Copy decorated queryset methods to manager too (#646)
* copy decorated queryset methods to manager too

* added test for from_manager with decorated queryset methods
2021-06-16 10:15:32 +03:00
Anton Agestam
96ae17f4a7 Add missing queryset annotations (#644) 2021-06-15 11:51:13 +03:00
Cesar Canassa
397e3f3dac Adds support for pyproject.toml files (#639)
* Adds support for pyproject.toml files

Since mypy 0.900 the pyproject.toml files are supported.

This PR adds a support for it. It searchs for a `tool.django-stubs` section. This is an example configuration:

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

Fixes #638

* Added TOML tests

* Use textwrap.dedent instead of trying to manually replace spaces
2021-06-15 01:50:31 +03:00
Maarten ter Huurne
8c387e85fe Allow Collection for 'fields' and 'exclude' of form model helpers (#637) (#640)
* Allow Collection for 'fields' and 'exclude' of form model helpers (#637)

There are several functions and classes in `django.forms.models` that
take a `fields` or `exclude` argument. Previously, `Sequence` was used
to annotate these, but the code of Django (I checked version 3.2.4)
doesn't require `__getitem__()` to be implemented, so requiring
`Collection` instead is sufficient.

The practical advantage of requiring `Collection` is that a set, such
as the key set of a dictionary, can be passed without first having to
convert it to a list or tuple.

* Pin mypy to below version 0.900

* Remove Callable for 'fields' and 'exclude' of form model helpers

I cannot find any support for callables for these two arguments in
the code or in the documentation.

* Update setup.py

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2021-06-12 01:21:42 +03:00
Cesar Canassa
77f9926ce1 fix tests for mypy 0.900 (#641) 2021-06-12 01:05:46 +03:00
Nikita Sobolev
47f1700a8b Update test.yml 2021-06-05 23:46:55 +03:00
Seth Yastrov
48c0bf0713 get_language can sometimes return None (#633)
https://docs.djangoproject.com/en/3.2/ref/utils/#django.utils.translation.get_language
> Returns the currently selected language code. Returns None if translations are temporarily deactivated (by deactivate_all() or when None is passed to override()).
2021-06-04 16:02:08 +03:00
jonfoster
893ad6bb02 #629: Add HTTP response "streaming" attribute (#632)
Add the missing attribute django.http.response.StreamingHttpResponse.streaming .

This is actually done by moving the attribute from HttpResponse to the base class HttpResponseBase.

The real Django source code declares this attribute on HttpResponse and StreamingHttpResponse, however that's only because Django doesn't have type hints.  The right place for the type hint is on the base class HttpResponseBase, since all instances of that base class are actually instances of HttpResponse or StreamingHttpResponse or a subclass of those two classes.  So it's guaranteed that every HttpResponseBase instance has the attribute.

Fixes bug #629.
2021-06-03 21:25:25 +03:00
Abhishek Chaudhary
becb0c9605 fix(ResolverMatch): Added _func_path (#631)
* fix(ResolverMatch): Added _func_path

ResolverMatch class in Django contains _func_path variable and it will get initialized in init method whatever the condition, so it should be added in type stubs as well. https://github.com/django/django/blob/main/django/urls/resolvers.py#L48

* Update resolvers.pyi

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2021-06-03 13:57:16 +03:00
Paweł Markowski
9a95b98398 add concrete attr to field (#623) 2021-05-25 18:22:48 +03:00
Nikita Sobolev
e12a2d9aef Update README.md 2021-05-24 11:56:08 +03:00
Y. Kiuchi
2f84d2e904 Add db_collation parameter to CharField and TextField (#621)
* Add db_collation parameter to CharField

* Add db_collation parameter to TextField
2021-05-24 11:22:07 +03:00
Nikita Sobolev
353b790209 Create py.typed 2021-05-21 11:00:24 +03:00
Bob Whitelock
66d5045ed9 Document limitation with django_stubs_ext.monkeypatch() (#619)
This monkey patching will only work when using Python 3.7+, which
introduced the `__class_getitem__` magic method. This tripped me up for
a while as I was on Python 3.6 and wondered why the monkey patching was
not working, therefore documenting this to point this out to future
readers.
2021-05-20 19:24:33 +03:00
Anton Agestam
3bd9fe530e Add stub for QuerySet.alias() (#618) 2021-05-19 16:23:59 +03:00
Anton Agestam
6dd8384381 Add stub for OpClass (#617) 2021-05-19 11:09:31 +03:00
Anton Agestam
248f1cccee Adjust Postgres indexes for Django 3.2 (#616) 2021-05-19 09:49:01 +03:00
Nikita Sobolev
c0203c9a60 Removes useless import 2021-05-17 22:06:32 +03:00
Marti Raudsepp
45f6dc0362 Improve hints for database connections (DatabaseWrapper) (#612)
* `django.db.{connection, connections, router}` are now hinted -- including `ConnectionHandler` and `ConnectionRouter` classes.
* Several improvements to `BaseDatabaseWrapper` attribute hints.
* In many places, database connections were hinted as `Any`, which I changed to `BaseDatabaseWrapper`.
* In a few places I added additional `SQLCompiler` hints.
* Minor tweaks to nearby code.
2021-05-13 20:22:35 +03:00
Marti Raudsepp
d1dd95181a Add a few missing Storage-related hints (#611) 2021-05-13 13:44:19 +03:00
Marti Raudsepp
e8d03a0e22 Use BaseDatabaseWrapper class instead of sqlite3's wrapper (#610)
Code dealing with DatabaseWrapper instances should be capable of dealing
with any database, not just sqlite3.
2021-05-13 13:38:08 +03:00
LanDinh
9251520f66 Allow Views to return the more generic HttpResponseBase instead of HttpResponse, to allow returning StreamingHttpResponse (#607)
* Add type hints for the postgres CursorDebugWrapper, expand the BaseCursorDebugWrapper.

* Fix how Optinal gets applied.

* Fix optional handling further.

* Adjust postgres debugcursorwrapper to look more like the implementation.

* Apply review feedback.

* Use the more generic HttpResponseBase when appriopriate.

* Fix failing test and add new test.

* Remove the other test again, it was the wrong location. Add new tests in the correct location.

Co-authored-by: LanDinh <coding+sourcetree@khaleesi.ninja>
2021-05-02 00:33:05 +03:00
Thomas Krapp
2a1c86744c Update decorators.pyi to match Django 3.1 (#576)
* Update decorators.pyi to match Django 3.1

This commit resembles the state of the file in Django 3.1. Unfortunately, this is not even compatible with Django 3.0 which misses the sync* and async* decorators.

* Update decorators.pyi

* Fixes lint

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2021-05-01 13:42:29 +03:00
Brian Helba
619823d497 Ensure that all registered checks return a list of CheckMessage (#508)
* Ensure that all registered checks return a list of CheckMessage

This changes missing and Any return types on registered checks to always
return "List[CheckMessage]".

In many cases, check functions were already annotated to return in a more
specific type than CheckMessage (e.g. Error). In these cases, it's assumed
that the existing annotation is correct, and the more specific type is kept.

* Update model_checks.pyi

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2021-05-01 13:34:38 +03:00
Sondre Lillebø Gundersen
e4de8453cf Replace models.Model annotations with type variables (#603)
* Replace models.Model annotations with type variables

* Adds generic type args to generic views

* Adds more tests

* Revert "Adds generic type args to generic views"

This reverts commit 6522f30cdb9027483f46d77167394c84eb7b7f4b.

* Adds Generic support for DetailView and ListView

Co-authored-by: sobolevn <mail@sobolevn.me>
2021-05-01 13:21:19 +03:00
Nikita Sobolev
5c3898d3b0 Revert "correct the type signature of AbstractBaseUser.set_password (#493)" (#537)
This reverts commit 8729a74f81.
2021-05-01 13:10:11 +03:00
Fabian Henze
e5ff9808cf Correct type of core.management.commands.runserver.Command.default_port (#604)
Strangely this variable is actually a string:
8bcb00858e/django/core/management/commands/runserver.py (L33)
2021-04-30 20:23:33 +03:00
Maxim Masiutin
c633f3215f Added a few definitions to resolve incompatibily with Pyre/Pysa (#601) 2021-04-24 08:24:49 +03:00
Abhyudai
9e8e4363b1 Update BaseCommand.requires_system_checks for django >=3.2 (#600)
- the documentation for this specific change in django can be seen at https://docs.djangoproject.com/en/3.2/howto/custom-management-commands/#django.core.management.BaseCommand.requires_system_checks
2021-04-22 19:11:22 +03:00
Simon Charette
d4c1ed2ce0 Handle GenericForeignKey class typeinfo lookup failure. (#597)
This addresses an obscure crash we're getting when defining a GenericForeignKey
subclass on a model.

Not sure how this slipped through type checking since
`helpers.lookup_class_typeinfo -> Optional[TypeInfo]` while
`.get_private_descriptor_type(type_info: TypeInfo)` so this should be a clear
type violation.
2021-04-21 09:44:41 +03:00
LanDinh
3931432b34 Add type hints for the postgres CursorDebugWrapper and add missing method to the BaseCursorDebugWrapper (#585)
* Add type hints for the postgres CursorDebugWrapper, expand the BaseCursorDebugWrapper.

* Fix how Optinal gets applied.

* Fix optional handling further.

* Adjust postgres debugcursorwrapper to look more like the implementation.

* Apply review feedback.

Co-authored-by: LanDinh <coding+sourcetree@khaleesi.ninja>
2021-04-18 13:50:25 +03:00
Stevan Milic
4c90b5098f Add no_key parameter to select_for_update queryset method (#594) (#595)
Co-authored-by: Stevan Milic <stevan.milic@tradecore.com>
2021-04-16 19:42:02 +03:00
sobolevn
488d17b65c django-stubs-ext@0.2.0 2021-04-14 12:59:57 +03:00
Daniel Hahler
ee58b18f15 WIP: django_stubs_ext: monkeypatch reveal_{type,locals} into builtins (#591)
* WIP: django_stubs_ext: monkeypatch `reveal_{type,locals}` into builtins

Fixes https://github.com/typeddjango/django-stubs/issues/590

* fixup! WIP: django_stubs_ext: monkeypatch `reveal_{type,locals}` into builtins

* fixup! fixup! WIP: django_stubs_ext: monkeypatch `reveal_{type,locals}` into builtins

* Update patch.py

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2021-04-14 12:33:45 +03:00