* Add/fix types for django.utils.safestring.mark_safe
Django code ref: 964dd4f4f2/django/utils/safestring.py (L71-L84)
* add generic annotations for mark_safe, remove SafeBytes as it is basically deprecated
Co-authored-by: Daniel Hahler <github@thequod.de>
* return corresponding descriptors for some related fields in class access
* return corresponding descriptors for file fields in class access
* fix tests
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.
* 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.
* 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.
- 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.
* 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.
* 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.