Commit Graph

75 Commits

Author SHA1 Message Date
Maxim Kurnikov
b6a5ccabdf move configuration to [mypy.plugins.django-stubs] inside mypy config file 2019-07-24 22:32:52 +03:00
Maxim Kurnikov
df021f6baa add some support for proxy models 2019-07-24 13:39:23 +03:00
Maxim Kurnikov
57796077c6 create(id=None) is valid, if id is AutoField 2019-07-24 13:38:50 +03:00
Maxim Kurnikov
a0db24c764 add objects to model, trade false positive for false negative 2019-07-24 13:38:49 +03:00
Maxim Kurnikov
39fb48b08a fix httprequest other fields 2019-07-24 13:38:49 +03:00
Maxim Kurnikov
d7d379e1cd create dummy classes for custom_manager_of_model usecase 2019-07-24 13:38:49 +03:00
Maxim Kurnikov
6962b42cba allow to use fields as Field objects outside Model classes 2019-07-24 13:38:49 +03:00
Maxim Kurnikov
b86d33c718 allow custom app label for ForeignKey 2019-07-24 13:38:49 +03:00
Maxim Kurnikov
fa57fb0cbf request.user has type of AUTH_USER_MODEL 2019-07-24 13:38:49 +03:00
Maxim Kurnikov
248504c25a various fixes 2019-07-24 13:38:49 +03:00
Maxim Kurnikov
fee4aad3d0 fix OneToOneField without related_name 2019-07-24 13:38:49 +03:00
Maxim Kurnikov
fc9843bea6 add support for _meta.get_field() typechecking 2019-07-24 13:38:49 +03:00
Maxim Kurnikov
5bb1bc250d add get_next_by_FOO, get_previous_by_FOO for date,datetime fields 2019-07-24 13:38:49 +03:00
Maxim Kurnikov
1721c997be add support for get_FIELD_display for choices fields 2019-07-24 13:38:49 +03:00
Maxim Kurnikov
bba6f769b5 add django.contrib.contenttypes to all tests by default 2019-07-24 13:38:49 +03:00
Maxim Kurnikov
f2e79d3bfb add GenericForeignKey support, remove some false-positives 2019-07-24 13:38:49 +03:00
Maxim Kurnikov
4f935edd47 add reverse lookups to values(), values_list() 2019-07-24 13:38:49 +03:00
Maxim Kurnikov
0e72b2e6fc more values(), values_list() cases 2019-07-24 13:38:49 +03:00
Maxim Kurnikov
b81fbdeaa9 remove -semanal suffix 2019-07-24 13:38:49 +03:00
Maxim Kurnikov
b11a9a85f9 new semanal wip 1 2019-07-24 13:38:49 +03:00
Maxim Kurnikov
9c5a6be9a7 split helpers into smaller files 2019-07-24 13:38:49 +03:00
Peter Law
861c6653fd Make SuccessMessageMixin fully compatible with FormMixin (#86)
This ensures that the order in which these mixins are included
into a derrived class does not matter and ends up more accurately
reflecting the return type of SuccessMessageMixin in the process
(its code doesn't appear to enforce that the returned response
is a redirect).

This provides a fix to a secondary aspect of
https://github.com/mkurnikov/django-stubs/issues/79.
2019-07-02 13:34:05 +03:00
Maxim Kurnikov
4e1c32f6a3 Fix mypy==0.710 errors (#97)
* error -> note for revealed type for tests

* fixes for latest mypy
2019-07-01 00:51:56 +03:00
Maxim Kurnikov
5dd6eccdb5 make ignore_missing_model_attributes behaviour optional (#66)
make "ignore_missing_model_attributes" behaviour opt-in
2019-04-12 17:22:18 +03:00
Maxim Kurnikov
aeb435c8b3 Disable monkeypatches, add dependencies via new hook (#60)
* code cleanups, disable monkeypatches, move to add_additional_deps

* disable incremental mode for tests

* add pip-wheel-metadata

* move some code from get_base_hook to get_attribute_hook to reduce dependencies

* simplify values/values_list tests and code

* disable cache for some tests failing with incremental mode

* enable incremental mode for tests typechecking

* pin mypy version

* fix tests

* lint

* fix internal crashes
2019-04-12 14:54:00 +03:00
Seth Yastrov
71fb0432f3 52/model subtypes dont typecheck (#55)
* Fix problem where Model instancess are not considered subtypes of each other due to fallback_to_any = True. Fixes #52.

- Added a stub for __getstate__ to Model.
- Added a stub for clean() to Model.
- Correct arg type for sort_dependencies so they are covariant (Iterable rather than List).

Test ignores:
- Added some test ignores in cases where a model inherits from 2 different base models.
- Added some test ignores for cases that MyPy flags as errors due to variable redefinitions or imports that are incompatible types.

* Address review comment.
2019-03-28 23:13:02 +03:00
Seth Yastrov
5b455b729a Specific return types for values and values list (#53)
* Instead of using Literal types, overload QuerySet.values_list in the plugin. Fixes #43.

- Add a couple of extra type checks that Django makes:
  1) 'flat' and 'named' can't be used together.
  2) 'flat' is not valid when values_list is called with more than one field.

* Determine better row types for values_list/values based on fields specified.

- In the case of values_list, we use a Row type with either a single primitive, Tuple, or NamedTuple.
- In the case of values, we use a TypedDict.
- In both cases, Any is used as a fallback for individual fields if those fields cannot be resolved.

A couple other fixes I made along the way:
- Don't create reverse relation for ForeignKeys with related_name='+'
- Don't skip creating other related managers in AddRelatedManagers if a dynamic value is encountered
  for related_name parameter, or if the type cannot be determined.

* Fix for TypedDict so that they are considered anonymous.

* Clean up some comments.

* Implement making TypedDict anonymous in a way that doesn't crash sometimes.

* Fix flake8 errors.

* Remove even uglier hack about making TypedDict anonymous.

* Address review comments. Write a few better comments inside tests.

* Fix crash when running with mypyc ("interpreted classes cannot inherit from compiled") due to the way I extended TypedDictType.

- Implemented the hack in another way that works on mypyc.
- Added a couple extra tests of accessing 'id' / 'pk' via values_list.

* Fix flake8 errors.

* Support annotation expressions (use type Any) for TypedDicts row types returned by values_list.

- Bonus points: handle values_list gracefully (use type Any) where Tuples are returned
  where some of the fields arguments are not string literals.
2019-03-25 12:53:09 +03:00
Maxim Kurnikov
5c6be7ad12 Add test to import all modules to check validity of stubs (#56)
* add import_all.test builder

* fix errors

* fix typechecking errors

* fix migrations typechecking
2019-03-25 01:57:34 +03:00
Seth Yastrov
b1a04d2f7d Instead of using Literal types, overload QuerySet.values_list in the plugin. Fixes #43. (#44)
- Add a couple of extra type checks that Django makes:
  1) 'flat' and 'named' can't be used together.
  2) 'flat' is not valid when values_list is called with more than one field.
2019-03-13 22:10:37 +03:00
Seth Yastrov
324b961d74 Support returning the correct values for the different QuerySet methods when using .values() and .values_list(). (#33)
* Support returning the correct values for the different QuerySet methods when using .values() and .values_list().

* Fix slicing on QuerySet. Fix django queries test, and remove some ignored errors that are no longer needed.

* Remove accidental change in RawQuerySet.

* Readded some still-necessary ignores to aggregation django test.

* Add more tests of first/last/earliest/last/__getitem__, per mkurnikov's comments.

- Fix .iterator()

* Re-add Iterator as base-class of QuerySet.

* Make QuerySet a Collection.

* - Fix return type for QuerySet.select_for_update().
- Use correct return type for QuerySet.dates() / QuerySet.datetimes().
- Use correct type params in return type for QuerySet.__and__ / QuerySet.__or__
- Re-add Sized as base class for QuerySet.
- Add test of .all() for all _Row types.
- Add test of .get() for all _Row types.
- Remove some redundant QuerySet method tests.

* Automatically fill in second type parameter for QuerySet.

... if second parameter is omitted.
2019-03-10 12:13:50 +03:00
Seth Yastrov
86c63d790b Fix type errors on other models' managers when using objects = models.Manager() in Model. (#34)
* Fix bug where models with a class variable using a manager defined would interfere with other managers.

- Fill in the type argument for that particular instance of the manager, rather than modifying the bases of the Manager type.
- Instantiate a new Instance from determine_proper_manager_type so The code doesn't crash under mypy-mypyc.

* Use helpers.reparametrize_instance per review comment.

* Updated ignored errors in Django test for get_objects_or_404.

- For some reason, `Manager[nothing]` is now removed from expected types.
  However, I think this makes sense anyway, as Manager is a subclass of QuerySet.
2019-03-08 12:30:38 +03:00
Richard Eames
f7dfbefbd6 Make CharField(blank=True) not be considered nullable (#39)
* Make CharField(blank=True) not be considered nullable

The documentation on [blank](https://docs.djangoproject.com/en/2.1/ref/models/fields/#blank) says that it "will allow the entry of an empty value", which for a string is just a 0-length string. This patch allows `CharField(blank=True,...)` to no longer be considered `Optional`.

closes #38

* fixed tests for `CharField(blank=True)`

* allow blank CharField to be nullable in the constructor, but the underlying type
is str (unless `null=True`)
2019-03-06 01:37:44 +03:00
Maxim Kurnikov
df5c70c703 fixes for FormMixin's get_form/get_form_class 2019-02-25 04:01:36 +03:00
Seth Yastrov
2dec3b4325 Merge branch 'master' into queryset_in_bulk 2019-02-22 08:16:48 +01:00
Seth Yastrov
3b8c5d08e8 QuerySet.in_bulk fixes.
- Made id_list of type Sequence[Any], rather than Any, according to mkurnikov's review.
- Removed **kwargs.
- Made returned Dict keys of type Any rather than int or str as it depends on the provided field's type.
- Added test with examples from Django docs.
2019-02-22 08:13:31 +01:00
Maxim Kurnikov
3d14d07e4e incremental = True for plugin tests should be fixed now 2019-02-21 17:35:46 +03:00
Maxim Kurnikov
6e6d1645d3 enable incremental mode for tests, disable it for one so that it would pass 2019-02-21 00:06:09 +03:00
Maxim Kurnikov
14ea848dd7 add nested Meta inheritance support for forms 2019-02-20 21:52:28 +03:00
Maxim Kurnikov
194258ab8e Merge pull request #23 from syastrov/better-types-for-transaction-atomic
Add better typings plus test for transaction.atomic.
2019-02-20 21:12:14 +03:00
Seth Yastrov
67c99434e5 Add better typings plus test for transaction.atomic.
- All cases are handled, including bare decorator (@transaction.atomic).
- Decorated function's signature is preserved when type-checking.
2019-02-20 06:40:22 +01:00
Maxim Kurnikov
5d8cdbcf29 fix integer set type 2019-02-20 02:38:45 +03:00
Maxim Kurnikov
ab73d53ae5 add support for models defined in the same module be specified as name of class in related fields 2019-02-19 00:43:27 +03:00
Maxim Kurnikov
f980311be0 finish strict_optional support, enable it for typechecking of django tests 2019-02-18 00:52:56 +03:00
Maxim Kurnikov
882ec71d23 remove redundant test 2019-02-17 18:08:58 +03:00
Maxim Kurnikov
e9f9202ed1 preliminary support for strict_optional 2019-02-17 18:07:53 +03:00
Maxim Kurnikov
c382d6aa2f fix redefining field with name id with different than int type 2019-02-15 21:54:40 +03:00
Maxim Kurnikov
a08ad80a0d fix star import parsing for settings 2019-02-14 03:16:07 +03:00
Maxim Kurnikov
f30cd092f1 add default for MYPY_DJANGO_CONFIG 2019-02-13 23:02:49 +03:00
Maxim Kurnikov
26a80a8279 add properly typed FOREIGN_KEY_FIELD_NAME_id fields to models 2019-02-13 21:05:02 +03:00
Maxim Kurnikov
4a22da29cb add support for default related managers, fixes #18 2019-02-13 17:11:22 +03:00