Skip to content

Commit

Permalink
refactor: fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
eginhard committed Apr 29, 2024
1 parent 705e513 commit 5ed0dc2
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion coqpit/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from coqpit.coqpit import MISSING, Coqpit, check_argument, dataclass
from coqpit.coqpit import MISSING, Coqpit, check_argument, dataclass # noqa: F401
5 changes: 2 additions & 3 deletions coqpit/coqpit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 💆
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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()


Expand Down
4 changes: 1 addition & 3 deletions tests/test_init_from_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_parse_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_serialization.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
"age": 15
}
]
}
}
2 changes: 1 addition & 1 deletion tests/test_simple_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5ed0dc2

Please sign in to comment.