Skip to content

Commit fae4aa6

Browse files
authored
SONARPY-2148: Add pytorch and torchvision custom stubs
1 parent 0ea90aa commit fae4aa6

File tree

161 files changed

+23608
-922
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

161 files changed

+23608
-922
lines changed

python-checks/src/main/java/org/sonar/python/checks/TorchModuleShouldCallInitCheck.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
@Rule(key = "S6978")
4343
public class TorchModuleShouldCallInitCheck extends PythonSubscriptionCheck {
44-
private static final String TORCH_NN_MODULE = "torch.nn.Module";
44+
private static final String TORCH_NN_MODULE = "torch.nn.modules.module.Module";
4545
private static final String MESSAGE = "Add a call to super().__init__().";
4646
private static final String SECONDARY_MESSAGE = "Inheritance happens here";
4747
public static final String QUICK_FIX_MESSAGE = "insert call to super constructor";

python-checks/src/test/java/org/sonar/python/checks/TorchModuleShouldCallInitCheckTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ void test() {
3333
void testQuickFix() {
3434
PythonQuickFixVerifier.verify(new TorchModuleShouldCallInitCheck(),
3535
"""
36-
import torch
36+
import torch.nn
3737
class Test(torch.nn.Module):
3838
def __init__(self):
3939
some_method()
4040
""",
4141
"""
42-
import torch
42+
import torch.nn
4343
class Test(torch.nn.Module):
4444
def __init__(self):
4545
super().__init__()
@@ -48,13 +48,13 @@ def __init__(self):
4848

4949
PythonQuickFixVerifier.verify(new TorchModuleShouldCallInitCheck(),
5050
"""
51-
import torch
51+
import torch.nn
5252
class Test(torch.nn.Module):
5353
def __init__(self):
5454
...
5555
""",
5656
"""
57-
import torch
57+
import torch.nn
5858
class Test(torch.nn.Module):
5959
def __init__(self):
6060
super().__init__()
@@ -63,14 +63,14 @@ def __init__(self):
6363

6464
PythonQuickFixVerifier.verifyNoQuickFixes(new TorchModuleShouldCallInitCheck(),
6565
"""
66-
import torch
66+
import torch.nn
6767
class Test(torch.nn.Module):
6868
def __init__(self): some_method()
6969
""");
7070

7171
PythonQuickFixVerifier.verifyNoQuickFixes(new TorchModuleShouldCallInitCheck(),
7272
"""
73-
import torch
73+
import torch.nn
7474
class Test(torch.nn.Module):
7575
def __init__(self): pass
7676
""");

0 commit comments

Comments
 (0)