Commit graph

1098 commits

Author SHA1 Message Date
pre-commit-ci[bot]
e4d6561a08
[pre-commit.ci] pre-commit autoupdate
updates:
- [github.com/PyCQA/flake8: 7.1.0 → 7.1.1](https://github.com/PyCQA/flake8/compare/7.1.0...7.1.1)
- [github.com/asottile/pyupgrade: v3.16.0 → v3.17.0](https://github.com/asottile/pyupgrade/compare/v3.16.0...v3.17.0)
2024-08-05 17:55:05 +00:00
Jelmer
731ed804f3
Merge pull request #603 from ProtixIT/type-annotations
Add type annotations
2024-06-19 17:24:56 +02:00
Jelmer
95664ef6ef
Merge pull request #623 from jazzband/pre-commit-ci-update-config
[pre-commit.ci] pre-commit autoupdate
2024-06-18 12:27:25 +02:00
pre-commit-ci[bot]
cc3a2b78b3
[pre-commit.ci] pre-commit autoupdate
updates:
- [github.com/PyCQA/flake8: 7.0.0 → 7.1.0](https://github.com/PyCQA/flake8/compare/7.0.0...7.1.0)
- [github.com/asottile/pyupgrade: v3.15.2 → v3.16.0](https://github.com/asottile/pyupgrade/compare/v3.15.2...v3.16.0)
2024-06-17 17:39:52 +00:00
Maarten ter Huurne
9dc224723b Tell coverage tool to ignore lines intended for mypy only
In particular, `if TYPE_CHECKING:` blocks and `...` in bodies of
overloaded method definitions.
2024-06-14 11:57:28 +02:00
Maarten ter Huurne
5fc37eb4b4 Provide type arguments to field base classes 2024-06-13 12:02:05 +02:00
Maarten ter Huurne
00937608fa Add type argument to DescriptorWrapper
This preserves the type of the wrapped descriptor (usually a field).

Maybe this is overkill, as `DescriptorWrapper` seems to only be used
as part of the `FieldTracker` implementation and is not documented
and barely tested. But technically, it is public API.
2024-06-13 12:02:05 +02:00
Maarten ter Huurne
1db7d6ba33 Fix type generics in InheritanceIterable 2024-06-13 12:02:05 +02:00
Maarten ter Huurne
f4653f08e5 Preserve tracked function's return type in FieldTracker 2024-06-13 12:02:05 +02:00
Maarten ter Huurne
23a756e13e Annotate test_fields package 2024-06-13 12:02:05 +02:00
Maarten ter Huurne
8f0b4ee2f8 Suppress mypy errors in field tracker tests
I can't find a way to inform mypy of the actual types without
duplicating a lot of test code.
2024-06-13 12:02:05 +02:00
Maarten ter Huurne
3c314234ff Drop uses of JoinManager from the tests
The `JoinManager` class is deprecated and not annotated.
2024-06-13 12:02:05 +02:00
Maarten ter Huurne
ecc7312bf4 Override signature of query-returning methods in InheritanceManager 2024-06-13 12:02:05 +02:00
Maarten ter Huurne
7d6cad0200 Annotate test_field_tracker module 2024-06-13 12:02:05 +02:00
Maarten ter Huurne
949d110d04 Annotate the test_models package 2024-06-13 12:02:05 +02:00
Maarten ter Huurne
e4c88103f5 Add pytest to type check dependencies
We also type check the unit tests and the unit tests now import
functionality from pytest.
2024-06-13 12:02:05 +02:00
Maarten ter Huurne
9d3940a6f2 Annotate the test_choices module
This required a bit of refactoring to get the type of `STATUS` correct
for each suite.

There are two cases which I decided not to support in the type system:
- passing a list instead of a tuple when defining an option group
- `in` checks using a data type that doesn't match the choices
2024-06-13 12:02:05 +02:00
Maarten ter Huurne
c83ef89bc9 Annotate test helpers 2024-06-13 12:02:05 +02:00
Maarten ter Huurne
23f1811b9d Annotate return type of test methods 2024-06-13 12:02:05 +02:00
Maarten ter Huurne
218843d754 Add minimal annotations to unit tests
These annotations are sufficient to pass mypy inspection if mypy is
configured to allow unannotated functions.
2024-06-13 12:02:05 +02:00
Maarten ter Huurne
aeeb69a9dd Enable postponed evaluation of annotations for all test modules
This allows using the latest annotation syntax supported by the type
checker regardless of the runtime Python version.
2024-06-13 12:02:05 +02:00
Maarten ter Huurne
713a3fec88 Make type aliases compatible with old Python versions 2024-06-13 12:02:05 +02:00
Maarten ter Huurne
2b0b4827a5 Annotate the choices module
The `Choices` constructor actually only accepts lists and tuples, not
arbitrary sequences. However, using `list` in the annotation opens
a can of worms related to type variance.
2024-06-13 12:02:05 +02:00
Maarten ter Huurne
ebfb3455dc Annotate the fields module 2024-06-13 12:02:05 +02:00
Maarten ter Huurne
172cc72ec6 Annotate the models module 2024-06-13 12:02:05 +02:00
Maarten ter Huurne
bde2d8f9a9 Annotate the managers module 2024-06-13 12:02:05 +02:00
Maarten ter Huurne
56ea527286 Annotate the tracker module 2024-06-13 12:02:05 +02:00
Maarten ter Huurne
632441ea53 Require full annotation in mypy configuration 2024-06-13 12:02:05 +02:00
Maarten ter Huurne
0043fedf46 Enable postponed evaluation of annotations for all source modules
This allows using the latest annotation syntax supported by the type
checker regardless of the runtime Python version.
2024-06-13 12:02:05 +02:00
Maarten ter Huurne
885da698d5 Upgrade mypy and django-stubs 2024-06-13 12:02:05 +02:00
Maarten ter Huurne
db9336031e Call Field.get_default() instead of _get_default()
We can call the inherited public method using `super()` instead of
calling the private method directly.
2024-06-13 12:02:05 +02:00
Maarten ter Huurne
04e152f879 Do not assume that default manager is named objects in join() 2024-06-13 12:02:05 +02:00
Jelmer
e35c72427b
Merge pull request #624 from ProtixIT/DescriptorWrapper-no-catch
Remove catching of `AttributeError` in `DescriptorWrapper`
2024-06-13 10:58:11 +02:00
Jelmer
4275f84e7c
Merge pull request #614 from ProtixIT/splitfield-notnone
Remove support for assigning `None` to a `SplitField`
2024-06-13 09:25:40 +02:00
Maarten ter Huurne
14cf1b0d40 Remove catching of AttributeError in DescriptorWrapper
This catch was introduced in #367, but subsequent discussion
in #370, #381 and #382 suggests that it wasn't the proper solution.

Now that `AbstractModelTrackerTests` is re-enabled and passing,
it becomes clear that `AttributeError` is no longer raised during
unit testing when using a recent Django version. Therefore I think
it is safe to remove the `try`/`except`.
2024-06-12 16:55:45 +02:00
Maarten ter Huurne
a6b0a2aff7 Fix and re-enable AbstractModelTrackerTests
There used to be a [bug in Django](https://code.djangoproject.com/ticket/30427)
that caused these tests to fail, according to the discussion of #370.
That bug was fixed in Django 4.0.

However, because the test model was using a `FieldTracker`
rather than a `ModelTracker`, all model-specific test cases
in `ModelTrackerTests` continued to fail.
2024-06-12 16:54:14 +02:00
Jelmer
324ea2bd25
Merge pull request #617 from jazzband/readme-update
Update README.rst
2024-05-14 08:21:54 +02:00
Jelmer
2d833de9fa
Merge pull request #615 from ProtixIT/deprecate-joinmanager
Deprecate `JoinManager` and `JoinManagerMixin`
2024-05-14 08:15:38 +02:00
jelmert
7d0f348cb5 Updated changelog to include 4.5.1 & 4.5.0 2024-05-03 15:20:48 +02:00
Jelmer
f20c3945ad
Merge pull request #618 from ProtixIT/joinqueryset-quoted
Remove `JoinQueryset.get_quoted_query()`
2024-05-02 12:52:23 +02:00
Maarten ter Huurne
2b2110f82e Remove JoinQueryset.get_quoted_query()
Pass the parameters to the DB API instead of quoting them ourselves.
2024-05-02 12:47:40 +02:00
Matt Seymour
ea5c2b845d
Update README.rst
Update readme.rst

Run tests section does not render on github correctly and this information
is available in docs.
2024-04-22 11:43:47 +01:00
Maarten ter Huurne
441618a790 Update manual to explain JoinQueryset instead of JoinManager 2024-04-17 17:28:25 +02:00
Maarten ter Huurne
1ca51a55ed Document deprecation of JoinManager in ChangeLog 2024-04-17 14:45:25 +02:00
Maarten ter Huurne
784bf50c09 Add deprecation warning to JoinManagerMixin 2024-04-17 14:45:16 +02:00
Jelmer
ba9ac5db81
Merge pull request #612 from ProtixIT/generate-custom-soft-delete-manager
Auto-generate manager implementation for `CustomSoftDelete`
2024-04-17 09:36:00 +02:00
Jelmer
06939835bc
Merge pull request #611 from ProtixIT/delete-keep_parents
Fix `SoftDeletableModel.delete()` forwarding positional args to superclass
2024-04-17 09:34:16 +02:00
Maarten ter Huurne
c2d6cb5021 Remove support for assigning None to a SplitField
This behavior wasn't documented and didn't fully work: it breaks
as soon as you try to save a model with a `None` value.
2024-04-16 08:05:13 +02:00
Maarten ter Huurne
512d0f1890 Avoid deprecated SoftDeletableModel.objects manager in tests
Use the `available_objects` manager instead.
2024-04-16 04:02:33 +02:00
Maarten ter Huurne
800961626a Move CustomSoftDeleteQuerySet to tests.models
The `CustomSoftDeleteQuerySet` class was the only code left in
the `test.managers` module, while it is not in fact a `Manager`.
2024-04-16 04:02:33 +02:00