Disabled reportUnnecessaryIsInstance check within assert statement.

This commit is contained in:
Eric Traut 2019-09-10 21:13:06 -07:00
parent eddadf4b13
commit 1bd3971f09
2 changed files with 12 additions and 0 deletions

View File

@ -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) {

View File

@ -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)