Commit Graph

44 Commits

Author SHA1 Message Date
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
fc9843bea6 add support for _meta.get_field() typechecking 2019-07-24 13:38:49 +03:00
Maxim Kurnikov
b81fbdeaa9 remove -semanal suffix 2019-07-24 13:38:49 +03:00
Maxim Kurnikov
dc6101b569 remove old semanal plugin data 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
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
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
5d0ee40ada Fix errors in db.models.expressions and db.models.functions.* (#54)
* fix errors at db.models.expressions and db.models.functions.*

* catch KeyError if QuerySet has not been loaded
2019-03-24 02:54:10 +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
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
dacf88c692 optimize hooks a bit 2019-02-22 00:12:23 +03:00
Maxim Kurnikov
14ea848dd7 add nested Meta inheritance support for forms 2019-02-20 21:52:28 +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
c1640b619f fix stale import 2019-02-14 03:21:11 +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
79ebe20f2e add more test folders 2019-02-13 19:44:25 +03:00
Maxim Kurnikov
70378b8f40 preserve fallback to Any for unrecognized field types for init/create 2019-02-13 17:00:35 +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
5f6f597266 add config file support 2019-02-09 03:21:49 +03:00
Maxim Kurnikov
916df1efb6 add Model.__init__ typechecking 2019-02-08 17:16:03 +03:00
Maxim Kurnikov
d4cb729c93 rework settings, add loading of the django.conf.global_settings, cleanups 2019-02-07 19:13:39 +03:00
Maxim Kurnikov
77aba97bdc remove legacy monkeypatch 2019-01-22 20:12:36 +03:00
Maxim Kurnikov
4f33f28ba2 fix tests 2019-01-22 19:30:09 +03:00
Maxim Kurnikov
3c3e9305f4 add support for Apps.get_model for migrations 2018-12-21 01:17:47 +03:00
Maxim Kurnikov
094b8421ab move to plugin common api, move to new functioncontext api 2018-12-19 02:41:28 +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