Commit graph

1078 commits

Author SHA1 Message Date
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
Maarten ter Huurne
68a4c14c74 Auto-generate manager implementation for CustomSoftDelete
Besides requiring less code, this also allows the django-stubs
mypy plugin to automatically generate a type-annotated version
of the manager.

Unfortunately, the plugin does not put a `ClassVar` annotation
on `objects`, which is why we need the suppression.
2024-04-16 04:02:12 +02:00
Maarten ter Huurne
2d7139363c Fix SoftDeletableModel.delete() forwarding positional args to superclass
The `soft` argument was made keyword-only, to avoid conflicts with new
positional arguments that might be added to Django. It was already
conflicting with the `keep_parents` argument.

The `using` argument is now passed to the superclass positionally,
as otherwise it can overlap with `*args`, resulting in a `TypeError`
on calls where `keep_parents` is passed positionally.
2024-04-11 16:45:32 +02:00
Maarten ter Huurne
a86c14e4e7
Remove excerpt field workaround for South FakeORM (#610)
* Remove excerpt field workaround for South FakeORM

South FakeORM hasn't been supported since fda2d39e, but the workaround
introduced in 9147becf evaded deletion. The `NoRendered` model was
removed in 9df3df99, but with that model gone, the `no_excerpt_field`
argument became obsolete as well.

* Document removal of `no_excerpt_field` in changelog
2024-04-10 14:17:34 +02:00
Jelmer
0fcfc113af
Merge pull request #601 from ProtixIT/mypy-in-ci
Enable static type checks using mypy in CI
2024-04-10 08:33:05 +02:00
Maarten ter Huurne
c75e54a1b8 Add mypy environment to tox configuration 2024-04-05 17:16:44 +02:00
Maarten ter Huurne
2f58a1160d Add minimal type annotations to make mypy pass
Avoid using `Self` as a type argument: for some reason this fails
when mypy has an empty cache, but passes when the cache has been
filled. Maybe it's a weird interaction between the mypy core and
the django-stubs plugin?
2024-04-05 17:16:06 +02:00
Maarten ter Huurne
441e3adee5 Make default port a string
Django can handle both strings and integers, but typeshed expects the
default value to match the mapping's value type.
2024-04-05 17:15:16 +02:00
Maarten ter Huurne
62cecfeb25 Suppress error about __version__ being None when not installed
Suppress rather than annotate, because people type checking against
`django-model-utils` will always have it installed and therefore
should not have to deal with `__version__` being `None`.
2024-04-05 17:15:16 +02:00
Maarten ter Huurne
f3335a7fe1 Add configuration for mypy
This does not require annotations yet, but it will check all code
outside of functions.
2024-04-05 17:15:16 +02:00
Maarten ter Huurne
07653f84f3 Add dependencies for static type checking 2024-04-05 17:12:35 +02:00
Guilherme Martins Crocetti
4c9d6eee13
feat(monitor): Change default to None when the field is marked as nullable and no default is provided (#599) 2024-04-04 10:26:17 +02:00
Jelmer
714632e8bf
Merge pull request #590 from foarsitter/unused_variable_levels
Levels variable is never set
2024-04-03 08:58:54 +02:00
Jelmer
53941ec7b4
Merge pull request #604 from ProtixIT/property-decorators
Modernize property definitions in `SplitText`
2024-04-03 08:54:31 +02:00
Maarten ter Huurne
d320924383
Forward additional arguments to contribute_to_class() to Django (#605)
* Pass additional arguments to superclass `contribute_to_class()`

In Django 3.2 there is an additional argument `private_only` and more
could be added in future versions.
2024-04-03 08:53:52 +02:00
Jelmer
23ea25a3ca
Merge pull request #606 from ProtixIT/keyword-only-cleanup
Modernize the way some keyword-only arguments are implemented
2024-04-03 08:53:09 +02:00
Jelmer
89653b2d24
Merge pull request #607 from ProtixIT/cleanup-factory
Minor cleanup of the code handling `UrlsafeTokenField`'s `factory` argument
2024-04-03 08:52:26 +02:00
Jelmer
9e71a46552
Merge pull request #608 from jazzband/translations
Updated translation files
2024-04-01 21:04:00 +02:00
Jelmer Draaijer
c6d686e418 Translation files 2024-04-01 15:09:46 +02:00
Maarten ter Huurne
6c5ed66ef2 Use callable() builtin function over isinstance(..., Callable)
This is slightly more compact, but the main motivation is to work
around the following mypy bug:

https://github.com/python/mypy/issues/3060
2024-03-26 14:09:03 +01:00
Maarten ter Huurne
e34de65480 Fix error message of UrlsafeTokenField's factory arg check 2024-03-26 14:08:49 +01:00