-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
torchfix: Refactor ERROR_CODE to be consistent (#46)
- Loading branch information
1 parent
86579eb
commit b2d55f8
Showing
13 changed files
with
187 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,29 @@ | ||
from ...common import TorchVisitor | ||
from ...common import TorchError, TorchVisitor | ||
|
||
|
||
class TorchScopedLibraryVisitor(TorchVisitor): | ||
""" | ||
Suggest `torch.library._scoped_library` for PyTorch tests. | ||
""" | ||
|
||
ERROR_CODE = "TOR901" | ||
MESSAGE = ( | ||
"Use `torch.library._scoped_library` instead of `torch.library.Library` " | ||
"in PyTorch tests files. See https://github.com/pytorch/pytorch/pull/118318 " | ||
"for details." | ||
) | ||
ERRORS = [ | ||
TorchError( | ||
"TOR901", | ||
( | ||
"Use `torch.library._scoped_library` " | ||
"instead of `torch.library.Library` " | ||
"in PyTorch tests files. " | ||
"See https://github.com/pytorch/pytorch/pull/118318 " | ||
"for details." | ||
), | ||
) | ||
] | ||
|
||
def visit_Call(self, node): | ||
qualified_name = self.get_qualified_name_for_call(node) | ||
if qualified_name == "torch.library.Library": | ||
self.add_violation(node, error_code=self.ERROR_CODE, message=self.MESSAGE) | ||
self.add_violation( | ||
node, | ||
error_code=self.ERRORS[0].error_code, | ||
message=self.ERRORS[0].message(), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.