-
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.
- Loading branch information
Showing
4 changed files
with
41 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import torch | ||
from torch.library import Library, impl, fallthrough_kernel | ||
my_lib1 = Library("aten", "IMPL") |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
3:11 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. |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import libcst as cst | ||
from ...common import TorchVisitor, LintViolation | ||
|
||
|
||
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." | ||
) | ||
|
||
def visit_Call(self, node): | ||
qualified_name = self.get_qualified_name_for_call(node) | ||
if qualified_name == "torch.library.Library": | ||
position_metadata = self.get_metadata( | ||
cst.metadata.WhitespaceInclusivePositionProvider, node | ||
) | ||
|
||
self.violations.append( | ||
LintViolation( | ||
error_code=self.ERROR_CODE, | ||
message=self.MESSAGE, | ||
line=position_metadata.start.line, | ||
column=position_metadata.start.column, | ||
node=node, | ||
replacement=None, | ||
) | ||
) |