mirror of
https://github.com/microsoft/pyright.git
synced 2024-10-27 03:12:44 +03:00
Disabled reportUnnecessaryIsInstance check within assert statement.
This commit is contained in:
parent
eddadf4b13
commit
1bd3971f09
@ -1550,6 +1550,15 @@ export class TypeAnalyzer extends ParseTreeWalker {
|
||||
return;
|
||||
}
|
||||
|
||||
// If this call is within an assert statement, we'll ignore it.
|
||||
let curNode: ParseNode | undefined = node;
|
||||
while (curNode) {
|
||||
if (curNode.nodeType === ParseNodeType.Assert) {
|
||||
return;
|
||||
}
|
||||
curNode = curNode.parent;
|
||||
}
|
||||
|
||||
if (node.leftExpression.nodeType !== ParseNodeType.Name ||
|
||||
node.leftExpression.nameToken.value !== 'isinstance' ||
|
||||
node.arguments.length !== 2) {
|
||||
|
@ -18,4 +18,7 @@ def foo(p1: int, p2: Union[int, str]):
|
||||
# This should generate an error because this is always true.
|
||||
f = isinstance(p1, int)
|
||||
|
||||
# This should not generate an error because it's within an assert.
|
||||
assert isinstance(p1, int)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user