mirror of
https://github.com/pytorch/pytorch.git
synced 2025-11-02 14:34:54 +08:00
[BE]: TRY002 - Ban raising vanilla exceptions (#124570)
Adds a ruff lint rule to ban raising raw exceptions. Most of these should at the very least be runtime exception, value errors, type errors or some other errors. There are hundreds of instance of these bad exception types already in the codebase, so I have noqa'd most of them. Hopefully this error code will get commiters to rethink what exception type they should raise when they submit a PR. I also encourage people to gradually go and fix all the existing noqas that have been added so they can be removed overtime and our exception typing can be improved. Pull Request resolved: https://github.com/pytorch/pytorch/pull/124570 Approved by: https://github.com/ezyang
This commit is contained in:
committed by
PyTorch MergeBot
parent
fd90991790
commit
c5fafe9f48
@ -57,7 +57,7 @@ class Unboxing:
|
||||
for arg in args:
|
||||
# expecting only Argument
|
||||
if not isinstance(arg.argument, Argument):
|
||||
raise Exception(
|
||||
raise Exception( # noqa: TRY002
|
||||
f"Unexpected argument type, expecting `Argument` but got {arg}"
|
||||
)
|
||||
argument: Argument = arg.argument
|
||||
@ -99,7 +99,9 @@ class Unboxing:
|
||||
arg_name=arg_name, out_name=out_name, t=t, ctype=ctype
|
||||
)
|
||||
else:
|
||||
raise Exception(f"Cannot handle type {t}. arg_name: {arg_name}")
|
||||
raise Exception( # noqa: TRY002
|
||||
f"Cannot handle type {t}. arg_name: {arg_name}"
|
||||
) # noqa: TRY002
|
||||
return out_name, ctype, code, decl
|
||||
|
||||
def _gen_code_base_type(
|
||||
|
||||
Reference in New Issue
Block a user