Commit Graph

32 Commits

Author SHA1 Message Date
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
Michael Aquilina
5c3ce171b2 Add more method signatures for _ValuesQuerySet (#661) 2021-07-03 20:12:05 +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
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
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
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
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
Cesar Canassa
77f9926ce1 fix tests for mypy 0.900 (#641) 2021-06-12 01:05:46 +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
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
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
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
Daniel Hahler
3c6f438cc9 build(deps-dev): remove/unpin mypy/typing-extensions (#593)
* build(deps-dev): remove/unpin mypy/typing-extensions

Closes https://github.com/typeddjango/django-stubs/issues/592.

* Update test_options.yml

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2021-04-14 12:27:15 +03:00
Hannes Ljungberg
e8a97e301c [3.2] Adjust model indexes (#587) 2021-04-13 13:18:13 +03:00
Hannes Ljungberg
e72cbb6eb5 [3.2] Add durable argument to atomic (#586)
* [3.2] Add durable argument to atomic

* Adjust compatibility table for 3.2

* Update README.md

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2021-04-13 13:17:30 +03:00
LanDinh
ceb08f1804 Add URLPattern options to django.url.conf since they were missing. (#583)
* Add URLPattern options to django.url.conf since they were missing.

* Fix some wording in the contribution guide & fix a reference to Django version 3.0, which has since been replaced by 3.1 as new stable version.

* My bad - I was misreading the type hints a bit here. Fix tests.

* We need to specify the List[Union[URLResolver, URLPattern]] upfront, since those don't accept List[URLResolver] as argument.

* Add test to ensure that path() accepts a mix of URLPatterns & URLResolvers.

Co-authored-by: LanDinh <coding+sourcetree@khaleesi.ninja>
2021-04-10 18:01:40 +03:00
Konstantin Alekseev
9beb5327de Create related managers from generated managers (#580) 2021-04-07 11:37:28 +03:00
Edwin Grubbs
8f97bf880d MIMEBase parameter for EmailMessage.attach() (#577)
* MIMEBase parameter for EmailMessage.attach()

* Added test_mail.yml

Co-authored-by: Edwin Grubbs <edwin.grubbs@motiva.com>
2021-04-02 00:21:21 +03:00
Anton Agestam
124d90794c Fix Field arguments variance (#573)
* Fix Field arguments variance

* fixup! Fix Field arguments variance

Test field can be used as bsse type
2021-03-07 13:32:56 +03:00
James Owen
6a6fd47f28 Tweak the constructor signature for ManyToManyField (#571)
Prior to this change, ManyToManyField was declared as being generic in
_ST and _GT, but also used the _T Typevar in its __init__ signature.
This caused mypy to add _T to the variables it was generic in when used
as an alias.

The symptom of this problem was that mypy would show an error with the
message "Type application has too few types (3 expected)" where a
ManyToManyField alias was declared, but adding an extra argument would
fail because the type only takes two arguments.

This change brings the signature of ManyToManyField in line with
ForeignKey and OneToOneField.
2021-03-04 12:23:13 +03:00
Tim Martin
a1334a70b9 Stricter return type annotations for template.Library (#541)
* Stricter return type annotations for template.Library

* Add some unit tests for the template library decorators
2021-01-20 23:11:02 +03:00
proxi
caaa23ab8f convince mypy that user.is_staff (and friends) are booleans (#542)
closes #512

Co-authored-by: proxi <51172302+3n-k1@users.noreply.github.com>
2020-12-16 23:28:01 +03:00
Lysandros Nikolaou
d9c851abce Do not force django.contrib.* dependencies (#535)
* Do not force django.contrib.* dependencies

Fixes #428.
Fixes #534.

* Add one more test with contenttypes installed, but auth not
2020-11-24 14:38:03 +03:00
proxy
aab8acf2ea change get_user to use a protocol requiring a session (#522)
* change get_user to use a protocol requiring a session
define a "_HasSession" protocol, and update contrib.auth.get_user to use it
get_user only requires a session field, and idiomatic django testing frequently calls get_user with a TestClient

* run black

* use union for get_user instead of a protocol

* create tests for get_user typechecking

* properly import test client
2020-11-07 11:38:45 +03:00
proxy
f08b428027 make FormMixin generic to allow proper typing for LoginView (#515)
closes #514
2020-10-31 21:53:45 +03:00
Na'aman Hirschfeld
44151c485d updated package setup (#485)
* updated package setup

* updated to use python 3.9

* fixed test runner

* fixed typecheck tests

* fixed discrepencies

* added override to runner

* updated travis

* updated pre-commit hooks

* updated dep
2020-10-29 11:59:48 +03:00