Commit Graph

30 Commits

Author SHA1 Message Date
Maxim Kurnikov
28a3f126ee make mypy.checker import locally to prevent import cycles 2019-04-01 19:39:50 +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
e0e8814804 Revert "dont convert to optional, if anytype"
This reverts commit 53f5d2214b.
2019-03-05 19:11:02 +03:00
Maxim Kurnikov
53f5d2214b dont convert to optional, if anytype 2019-03-05 18:43:10 +03:00
Maxim Kurnikov
c962b8ac68 attempt to add flake8 and isort 2019-03-01 02:07:53 +03:00
Maxim Kurnikov
df5c70c703 fixes for FormMixin's get_form/get_form_class 2019-02-25 04:01:36 +03:00
Maxim Kurnikov
14ea848dd7 add nested Meta inheritance support for forms 2019-02-20 21:52:28 +03: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
e9f9202ed1 preliminary support for strict_optional 2019-02-17 18:07:53 +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
b7f7713c5a add support for get_user_model(), fixes #16 2019-02-13 15:56:21 +03:00
Maxim Kurnikov
9eb95fbab3 add BaseManager.create() typechecking 2019-02-12 03:54:48 +03:00
Maxim Kurnikov
6b7507206a fix couple edge cases with __init__ 2019-02-10 04:32:27 +03:00
Maxim Kurnikov
916df1efb6 add Model.__init__ typechecking 2019-02-08 17:16:03 +03:00
Maxim Kurnikov
87877774cd fix problems with 0.660 2019-01-20 18:57:26 +03:00
Maxim Kurnikov
f070098ce5 self reference support for foreignkeys 2018-12-21 23:46:10 +03:00
Maxim Kurnikov
3c3e9305f4 add support for Apps.get_model for migrations 2018-12-21 01:17:47 +03:00
Maxim Kurnikov
c9ad40d7e3 add support for managers as generics 2018-12-07 22:11:22 +03:00
Maxim Kurnikov
3676cb3ac0 solve more use cases for related managers and settings 2018-12-03 01:57:46 +03:00
Maxim Kurnikov
fcd659837e cleanups, fix settings 2018-12-01 16:26:53 +03:00
Maxim Kurnikov
60b1c48ade nested class Meta support 2018-11-30 14:00:11 +03:00
Maxim Kurnikov
64bc053056 move to custom pytest plugin test runner, fix tests, add Any fallback to ForeignKey 2018-11-28 00:37:04 +03:00
Maxim Kurnikov
f59cfe6371 latest changes 2018-11-26 23:58:34 +03:00
Maxim Kurnikov
06bb3cd50b add support for django.conf.settings.SETTING_NAME 2018-11-18 15:58:17 +03:00
Maxim Kurnikov
41cc79b957 support for models.Model.objects, abstract mixins 2018-11-14 02:33:50 +03:00
Maxim Kurnikov
2cdefc4662 more fixes for django stubs, first attempt for a plugin 2018-10-12 01:56:25 +03:00
Maxim Kurnikov
3d7b517e59 support for some Field -> builtin type mapping, OneToOneField, ForeignKey 2018-10-04 03:35:09 +03:00
Maxim Kurnikov
f500391748 initial work for django plugin 2018-10-04 03:35:09 +03:00