From 5ed0dc23a13efbb159d8054b6cb0dcc67cb8bbab Mon Sep 17 00:00:00 2001 From: Enno Hermann Date: Mon, 29 Apr 2024 22:28:12 +0200 Subject: [PATCH] refactor: fix lint errors --- LICENSE.txt | 2 +- coqpit/__init__.py | 2 +- coqpit/coqpit.py | 5 ++--- setup.py | 4 ++-- tests/test_init_from_dict.py | 4 +--- tests/test_parse_argparse.py | 6 +++--- tests/test_serialization.json | 2 +- tests/test_simple_config.py | 2 +- 8 files changed, 12 insertions(+), 15 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index f82557b..d3e759d 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021 Coqui +Copyright (c) 2021 Coqui Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/coqpit/__init__.py b/coqpit/__init__.py index 36fc452..b8b2c4b 100644 --- a/coqpit/__init__.py +++ b/coqpit/__init__.py @@ -1 +1 @@ -from coqpit.coqpit import MISSING, Coqpit, check_argument, dataclass +from coqpit.coqpit import MISSING, Coqpit, check_argument, dataclass # noqa: F401 diff --git a/coqpit/coqpit.py b/coqpit/coqpit.py index e214c8b..1cd0821 100644 --- a/coqpit/coqpit.py +++ b/coqpit/coqpit.py @@ -132,7 +132,7 @@ def _is_optional_field(field) -> bool: bool: True if the input field is optional. """ # return isinstance(field.type, _GenericAlias) and type(None) in getattr(field.type, "__args__") - return type(None) in getattr(field.type, "__args__") + return type(None) in field.type.__args__ def my_get_type_hints( @@ -342,7 +342,6 @@ def _validate_contracts(self): dataclass_fields = fields(self) for field in dataclass_fields: - value = getattr(self, field.name) if value is None: @@ -723,7 +722,7 @@ def load_json(self, file_name: str) -> None: Returns: Coqpit: new Coqpit with updated config fields. """ - with open(file_name, "r", encoding="utf8") as f: + with open(file_name, encoding="utf8") as f: input_str = f.read() dump_dict = json.loads(input_str) # TODO: this looks stupid 💆 diff --git a/setup.py b/setup.py index 076508f..4e12347 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ def create_version_file(): print("-- Building version " + version) version_path = os.path.join(cwd, "version.py") with open(version_path, "w") as f: - f.write("__version__ = '{}'\n".format(version)) + f.write(f"__version__ = '{version}'\n") class develop(setuptools.command.develop.develop): @@ -30,7 +30,7 @@ def run(self): setuptools.command.develop.develop.run(self) -with open("README.md", "r", encoding="utf-8") as readme_file: +with open("README.md", encoding="utf-8") as readme_file: README = readme_file.read() diff --git a/tests/test_init_from_dict.py b/tests/test_init_from_dict.py index 8c26faf..b443523 100644 --- a/tests/test_init_from_dict.py +++ b/tests/test_init_from_dict.py @@ -32,9 +32,7 @@ class WithRequired(Coqpit): def test_new_from_dict(): ref_config = Reference(name="Fancy", size=3**10, people=[Person(name="Anonymous", age=42)]) - new_config = Reference.new_from_dict( - {"name": "Fancy", "size": 3**10, "people": [{"name": "Anonymous", "age": 42}]} - ) + new_config = Reference.new_from_dict({"name": "Fancy", "size": 3**10, "people": [{"name": "Anonymous", "age": 42}]}) # check values assert len(ref_config) == len(new_config) diff --git a/tests/test_parse_argparse.py b/tests/test_parse_argparse.py index 1265b3c..6c7b00e 100644 --- a/tests/test_parse_argparse.py +++ b/tests/test_parse_argparse.py @@ -114,8 +114,8 @@ class Config(Coqpit): try: config.parse_args(args) - assert False, "should not reach this" - except: # pylint: disable=bare-except + assert False, "should not reach this" # noqa: B011 + except: # noqa: E722 pass @@ -129,7 +129,7 @@ def test_argparse_with_required_field(): try: c = ArgparseWithRequiredField() # pylint: disable=no-value-for-parameter c.parse_args(args) - assert False + assert False # noqa: B011 except TypeError: # __init__ should fail due to missing val_a pass diff --git a/tests/test_serialization.json b/tests/test_serialization.json index 8c110e4..e90dd3a 100644 --- a/tests/test_serialization.json +++ b/tests/test_serialization.json @@ -15,4 +15,4 @@ "age": 15 } ] -} \ No newline at end of file +} diff --git a/tests/test_simple_config.py b/tests/test_simple_config.py index 9485ca6..5b4dadf 100644 --- a/tests/test_simple_config.py +++ b/tests/test_simple_config.py @@ -39,7 +39,7 @@ def test_simple_config(): # try MISSING class argument try: - config.val_k + _ = config.val_k except AttributeError: print(" val_k needs a different value before accessing it.") config.val_k = 1000