From 19f0ddb33699a12dba0a4372bb8c76a74cbd3e1b Mon Sep 17 00:00:00 2001 From: Swen Kooij Date: Sat, 19 Oct 2019 13:04:53 +0300 Subject: [PATCH] Fix some flake8/pycodestyle issues --- localized_fields/forms.py | 12 ++++-------- requirements/test.txt | 1 - setup.cfg | 6 +----- setup.py | 15 +++++---------- tests/test_widget.py | 2 +- 5 files changed, 11 insertions(+), 25 deletions(-) diff --git a/localized_fields/forms.py b/localized_fields/forms.py index 19415ab..314dab3 100644 --- a/localized_fields/forms.py +++ b/localized_fields/forms.py @@ -55,7 +55,7 @@ class LocalizedFieldForm(forms.MultiValueField): for field, widget in zip(self.fields, self.widget.widgets): widget.is_required = field.required - def compress(self, value: List[str]) -> value_class: + def compress(self, value: List[str]) -> LocalizedValue: """Compresses the values from individual fields into a single :see:LocalizedValue instance. @@ -123,13 +123,8 @@ class LocalizedFileFieldForm(LocalizedFieldForm, forms.FileField): clean_data = [] errors = [] if not value or isinstance(value, (list, tuple)): - if ( - not value - or not [v for v in value if v not in self.empty_values] - ) and ( - not initial - or not [v for v in initial if v not in self.empty_values] - ): + is_empty = [v for v in value if v not in self.empty_values] + if (not value or not is_empty) and (not initial or not is_empty): if self.required: raise ValidationError( self.error_messages["required"], code="required" @@ -143,6 +138,7 @@ class LocalizedFileFieldForm(LocalizedFieldForm, forms.FileField): field_value = value[i] except IndexError: field_value = None + try: field_initial = initial[i] except IndexError: diff --git a/requirements/test.txt b/requirements/test.txt index bcccac9..6d74268 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -3,7 +3,6 @@ # Analysis black==19.3b0 flake8==3.7.7 -pycodestyle==2.5.0 autoflake==1.3 autopep8==1.4.4 isort==4.3.20 diff --git a/setup.cfg b/setup.cfg index 08724d8..66ce13c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,11 +1,7 @@ [flake8] -ignore = E252,E501 +ignore = E252,E501,W503 exclude = env,.tox,.git,config/settings,*/migrations/*,*/static/CACHE/*,docs,node_modules -[pycodestyle] -ignore = E501 -exclude=env,.tox,.git,*/migrations/*,*/static/CACHE/*,docs,node_modules - [isort] line_length=80 multi_line_output=3 diff --git a/setup.py b/setup.py index 47eab1d..79885f0 100644 --- a/setup.py +++ b/setup.py @@ -62,10 +62,7 @@ setup( cmdclass={ "lint": create_command( "Lints the code", - [ - ["flake8", "setup.py", "localized_fields", "tests"], - ["pycodestyle", "setup.py", "localized_fields", "tests"], - ], + [["flake8", "setup.py", "localized_fields", "tests"]], ), "lint_fix": create_command( "Lints the code", @@ -132,12 +129,10 @@ setup( "verify": create_command( "Verifies whether the code is auto-formatted and has no linting errors", [ - [ - ["python", "setup.py", "format_verify"], - ["python", "setup.py", "format_docstrings_verify"], - ["python", "setup.py", "sort_imports_verify"], - ["python", "setup.py", "lint"], - ] + ["python", "setup.py", "format_verify"], + ["python", "setup.py", "format_docstrings_verify"], + ["python", "setup.py", "sort_imports_verify"], + ["python", "setup.py", "lint"], ], ), "test": create_command( diff --git a/tests/test_widget.py b/tests/test_widget.py index ccd6a07..580d7d9 100644 --- a/tests/test_widget.py +++ b/tests/test_widget.py @@ -82,4 +82,4 @@ class LocalizedFieldWidgetTestCase(TestCase): widget = LocalizedFieldWidget() output = widget.render(name="title", value=None) - assert bool(re.search("