Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: enable B904 #3956

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/find_tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def find_tensorflow() -> Tuple[Optional[str], List[str]]:
)
tf_version = "2.14.1"
else:
raise RuntimeError("Unsupported CUDA version")
raise RuntimeError("Unsupported CUDA version") from None
requires.extend(get_tf_requirement(tf_version)["cpu"])
# setuptools will re-find tensorflow after installing setup_requires
tf_install_dir = None
Expand Down
6 changes: 4 additions & 2 deletions deepmd/dpmodel/descriptor/descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@
if cls is DescriptorBlock:
try:
descrpt_type = kwargs["type"]
except KeyError:
raise KeyError("the type of DescriptorBlock should be set by `type`")
except KeyError as e:
raise KeyError(

Check warning on line 43 in deepmd/dpmodel/descriptor/descriptor.py

View check run for this annotation

Codecov / codecov/patch

deepmd/dpmodel/descriptor/descriptor.py#L42-L43

Added lines #L42 - L43 were not covered by tests
"the type of DescriptorBlock should be set by `type`"
) from e
cls = cls.get_class_by_type(descrpt_type)
return super().__new__(cls)

Expand Down
4 changes: 2 additions & 2 deletions deepmd/entrypoints/neighbor_stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@
backends = Backend.get_backends_by_feature(Backend.Feature.NEIGHBOR_STAT)
try:
backend_obj = backends[backend]()
except KeyError:
raise ValueError(f"Invalid backend {backend}")
except KeyError as e:
raise ValueError(f"Invalid backend {backend}") from e

Check warning on line 79 in deepmd/entrypoints/neighbor_stat.py

View check run for this annotation

Codecov / codecov/patch

deepmd/entrypoints/neighbor_stat.py#L78-L79

Added lines #L78 - L79 were not covered by tests
NeighborStat = backend_obj.neighbor_stat
all_sys = expand_sys_str(system)
if not len(all_sys):
Expand Down
6 changes: 4 additions & 2 deletions deepmd/pt/model/descriptor/descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@
if cls is DescriptorBlock:
try:
descrpt_type = kwargs["type"]
except KeyError:
raise KeyError("the type of DescriptorBlock should be set by `type`")
except KeyError as e:
raise KeyError(

Check warning on line 52 in deepmd/pt/model/descriptor/descriptor.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/model/descriptor/descriptor.py#L51-L52

Added lines #L51 - L52 were not covered by tests
"the type of DescriptorBlock should be set by `type`"
) from e
cls = cls.get_class_by_type(descrpt_type)
return super().__new__(cls)

Expand Down
4 changes: 2 additions & 2 deletions deepmd/utils/data_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@
words = self.test_size.split("%")
try:
percent = int(words[0])
except ValueError:
raise RuntimeError("unknown test_size rule " + words[0])
except ValueError as e:
raise RuntimeError("unknown test_size rule " + words[0]) from e

Check warning on line 200 in deepmd/utils/data_system.py

View check run for this annotation

Codecov / codecov/patch

deepmd/utils/data_system.py#L199-L200

Added lines #L199 - L200 were not covered by tests
self.test_size = self._make_auto_ts(percent)
elif isinstance(self.test_size, list):
pass
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ select = [
"TID251", # banned-api
"TID253", # banned-module-level-imports
"T20", # ban print
"B904", # raise-without-from-inside-except
]

ignore = [
Expand Down
8 changes: 4 additions & 4 deletions source/tests/common/test_argument_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@ def run_test(self, *, command: str, mapping: "TEST_DICT"):
try:
with redirect_stderr(buffer):
namespace = parse_args(cmd_args)
except SystemExit:
except SystemExit as e:
raise SystemExit(
f"Encountered expection when parsing arguments ->\n\n"
f"{buffer.getvalue()}\n"
f"passed in arguments were: {cmd_args}\n"
f"built from dict {mapping}"
)
) from e
self.attr_and_type_check(namespace, mapping, command, test_value=True)

# check for required arguments
Expand All @@ -189,13 +189,13 @@ def run_test(self, *, command: str, mapping: "TEST_DICT"):
try:
with redirect_stderr(buffer):
namespace = parse_args(cmd_args)
except SystemExit:
except SystemExit as e:
raise SystemExit(
f"Encountered expection when parsing DEFAULT arguments ->\n\n"
f"{buffer.getvalue()}\n"
f"passed in arguments were: {cmd_args}\n"
f"built from dict {mapping}"
)
) from e
self.attr_and_type_check(namespace, mapping, command, test_value=False)

def test_no_command(self):
Expand Down
4 changes: 2 additions & 2 deletions source/tests/tf/test_parallel_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class TestSingleMachine(unittest.TestCase):
def setUp(self):
try:
import horovod # noqa: F401
except ImportError:
except ImportError as e:
raise unittest.SkipTest(
"Package horovod is required for parallel-training tests."
)
) from e
self.input_file = str(tests_path / "model_compression" / "input.json")

def test_two_workers(self):
Expand Down