Skip to content

Commit 2151bf1

Browse files
Fix FQN of unittest.mock.Mock (#678)
1 parent bd98741 commit 2151bf1

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,6 @@ private static int firstParameterOffset(FunctionSymbol functionSymbol, boolean i
219219
private static boolean isException(InferredType inferredType) {
220220
return SymbolUtils.externalModulesSymbols().values()
221221
.stream().flatMap(Collection::stream)
222-
.anyMatch(symbol -> inferredType.canBeOrExtend(symbol.fullyQualifiedName())) || inferredType.canBeOrExtend("unittest.Mock");
222+
.anyMatch(symbol -> inferredType.canBeOrExtend(symbol.fullyQualifiedName())) || inferredType.canBeOrExtend("unittest.mock.Mock");
223223
}
224224
}

python-checks/src/test/resources/checks/argumentType.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import genericpath
66
import _heapq
77
import imaplib
8-
import unittest
8+
from unittest.mock import Mock
99
from typing import Dict, Tuple, Set
1010
from collections import OrderedDict, Counter
1111

@@ -163,6 +163,6 @@ def method_with_multiple_decorators(y: str): ...
163163
A.method_with_multiple_decorators(42) # OK, multiple decorators
164164

165165
def exception_for_unittest_mock():
166-
class SomeMock(unittest.Mock): ...
166+
class SomeMock(Mock): ...
167167
my_mock = SomeMock()
168168
hex(my_mock) # OK

0 commit comments

Comments
 (0)