From 71ce3a288e1ab82dd797e018c8514b0c3e3f49c8 Mon Sep 17 00:00:00 2001 From: Roman Selivanov Date: Fri, 9 Jul 2021 14:22:59 +0300 Subject: [PATCH 1/4] Fix type hint for `required` kwarg --- localized_fields/fields/field.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/localized_fields/fields/field.py b/localized_fields/fields/field.py index 1047f0e..1817e7e 100644 --- a/localized_fields/fields/field.py +++ b/localized_fields/fields/field.py @@ -28,18 +28,26 @@ class LocalizedField(HStoreField): descriptor_class = LocalizedValueDescriptor def __init__( - self, *args, required: Union[bool, List[str]] = None, **kwargs + self, + *args, + required: Optional[Union[bool, List[str]]] = None, + blank: bool = False, + **kwargs ): """Initializes a new instance of :see:LocalizedField.""" - super(LocalizedField, self).__init__(*args, required=required, **kwargs) - - if (self.required is None and self.blank) or self.required is False: + if (required is None and blank) or required is False: self.required = [] - elif self.required is None and not self.blank: + elif required is None and not blank: self.required = [settings.LANGUAGE_CODE] - elif self.required is True: + elif required is True: self.required = [lang_code for lang_code, _ in settings.LANGUAGES] + else: + self.required = required + + super(LocalizedField, self).__init__( + *args, required=self.required, blank=blank, **kwargs + ) def contribute_to_class(self, model, name, **kwargs): """Adds this field to the specifed model. From 858fda5a58f12e4a5a37c5d412e4b31710c4fd9a Mon Sep 17 00:00:00 2001 From: Swen Kooij Date: Tue, 2 Jul 2024 06:33:38 +0300 Subject: [PATCH 2/4] Pin `click` version for Black --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index b076389..51ec29b 100644 --- a/setup.py +++ b/setup.py @@ -98,6 +98,7 @@ def run(self): "autopep8==1.4.4", "isort==4.3.20", "sl-docformatter==1.4", + "click==8.0.2", ], }, cmdclass={ From 953611ee38ae8590f66189f7140027cb53b60c8c Mon Sep 17 00:00:00 2001 From: Swen Kooij Date: Tue, 2 Jul 2024 06:33:55 +0300 Subject: [PATCH 3/4] Make Django tests use `USE_TZ = True` to silence Django 5.x deprecation warning --- settings.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/settings.py b/settings.py index b4680b8..42be8fe 100644 --- a/settings.py +++ b/settings.py @@ -1,3 +1,4 @@ +import django import dj_database_url DEBUG = True @@ -51,6 +52,12 @@ 'django.contrib.auth.middleware.AuthenticationMiddleware', ] +# See: https://github.com/psycopg/psycopg2/issues/1293 +if django.VERSION >= (3, 1): + USE_TZ = True + USE_I18N = True + TIME_ZONE = 'UTC' + # set to a lower number than the default, since # we want the tests to be fast, default is 100 LOCALIZED_FIELDS_MAX_RETRIES = 3 From d5551f6a346878799fa1c304fae802dc7b557a4f Mon Sep 17 00:00:00 2001 From: Swen Kooij Date: Tue, 2 Jul 2024 06:49:15 +0300 Subject: [PATCH 4/4] Silence our own deprecation warning when running the tests --- pytest.ini | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pytest.ini b/pytest.ini index 143a359..b1ab484 100644 --- a/pytest.ini +++ b/pytest.ini @@ -3,3 +3,5 @@ DJANGO_SETTINGS_MODULE=settings testpaths=tests addopts=-m "not benchmark" junit_family=legacy +filterwarnings= + ignore::DeprecationWarning:localized_fields.fields.autoslug_field