From 027bce0935eafdf39c95b3d12d9d42ee59feabe8 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Sun, 24 Sep 2023 14:30:04 +0200 Subject: [PATCH] Fix linter --- openfisca_core/entities/entity.py | 2 +- .../taxbenefitsystems/tax_benefit_system.py | 8 ++++---- openfisca_core/variables/variable.py | 2 +- openfisca_web_api/loader/variables.py | 16 ++++------------ .../tax_scales/test_abstract_rate_tax_scale.py | 2 +- tests/core/tax_scales/test_abstract_tax_scale.py | 2 +- 6 files changed, 12 insertions(+), 20 deletions(-) diff --git a/openfisca_core/entities/entity.py b/openfisca_core/entities/entity.py index b5344dbe58..62c803bd82 100644 --- a/openfisca_core/entities/entity.py +++ b/openfisca_core/entities/entity.py @@ -24,7 +24,7 @@ def set_tax_benefit_system(self, tax_benefit_system: TaxBenefitSystem): self._tax_benefit_system = tax_benefit_system def check_role_validity(self, role: Any) -> None: - if role is not None and not type(role) == Role: + if role is not None and not isinstance(role, Role): raise ValueError("{} is not a valid role".format(role)) def get_variable( diff --git a/openfisca_core/taxbenefitsystems/tax_benefit_system.py b/openfisca_core/taxbenefitsystems/tax_benefit_system.py index 271f77ba5e..812448ae1d 100644 --- a/openfisca_core/taxbenefitsystems/tax_benefit_system.py +++ b/openfisca_core/taxbenefitsystems/tax_benefit_system.py @@ -236,7 +236,7 @@ def add_variables_from_file(self, file_path): sys.modules[module_name] = module lines = linecache.getlines(file_path, module.__dict__) - source = ''.join(lines) + source = "".join(lines) tree = ast.parse(source) defs = {i.name: i for i in tree.body if isinstance(i, ast.ClassDef)} spec.loader.exec_module(module) @@ -262,9 +262,9 @@ def add_variables_from_file(self, file_path): class_def = defs[pot_variable.__name__] pot_variable.introspection_data = ( source_file_path, - ''.join(lines[class_def.lineno-1:class_def.end_lineno]), - class_def.lineno-1 - ) + "".join(lines[class_def.lineno - 1 : class_def.end_lineno]), + class_def.lineno - 1, + ) self.add_variable(pot_variable) except Exception: log.error( diff --git a/openfisca_core/variables/variable.py b/openfisca_core/variables/variable.py index f0a88ea8df..33cae3b20d 100644 --- a/openfisca_core/variables/variable.py +++ b/openfisca_core/variables/variable.py @@ -368,7 +368,7 @@ def get_introspection_data(cls): try: return cls.introspection_data except AttributeError: - return '', None, 0 + return "", None, 0 def get_formula( self, diff --git a/openfisca_web_api/loader/variables.py b/openfisca_web_api/loader/variables.py index ae6054c058..f9b6e05887 100644 --- a/openfisca_web_api/loader/variables.py +++ b/openfisca_web_api/loader/variables.py @@ -38,9 +38,7 @@ def build_source_url( ) -def build_formula( - formula, country_package_metadata, source_file_path -): +def build_formula(formula, country_package_metadata, source_file_path): source_code, start_line_number = inspect.getsourcelines(formula) source_code = textwrap.dedent("".join(source_code)) @@ -58,13 +56,9 @@ def build_formula( return api_formula -def build_formulas( - formulas, country_package_metadata, source_file_path -): +def build_formulas(formulas, country_package_metadata, source_file_path): return { - start_date: build_formula( - formula, country_package_metadata, source_file_path - ) + start_date: build_formula(formula, country_package_metadata, source_file_path) for start_date, formula in formulas.items() } @@ -97,9 +91,7 @@ def build_variable(variable, country_package_metadata): if len(variable.formulas) > 0: result["formulas"] = build_formulas( - variable.formulas, - country_package_metadata, - source_file_path + variable.formulas, country_package_metadata, source_file_path ) if variable.end: diff --git a/tests/core/tax_scales/test_abstract_rate_tax_scale.py b/tests/core/tax_scales/test_abstract_rate_tax_scale.py index 3d284a49e9..3d906dfcb4 100644 --- a/tests/core/tax_scales/test_abstract_rate_tax_scale.py +++ b/tests/core/tax_scales/test_abstract_rate_tax_scale.py @@ -6,4 +6,4 @@ def test_abstract_tax_scale(): with pytest.warns(DeprecationWarning): result = taxscales.AbstractRateTaxScale() - assert type(result) == taxscales.AbstractRateTaxScale + assert isinstance(result, taxscales.AbstractRateTaxScale) diff --git a/tests/core/tax_scales/test_abstract_tax_scale.py b/tests/core/tax_scales/test_abstract_tax_scale.py index f6834e7dc7..7746ea03ae 100644 --- a/tests/core/tax_scales/test_abstract_tax_scale.py +++ b/tests/core/tax_scales/test_abstract_tax_scale.py @@ -6,4 +6,4 @@ def test_abstract_tax_scale(): with pytest.warns(DeprecationWarning): result = taxscales.AbstractTaxScale() - assert type(result) == taxscales.AbstractTaxScale + assert isinstance(result, taxscales.AbstractTaxScale)