PY-21474 Fixed: Type checking confused by None default argument

PyTypeAssertionEvaluator: Mark reference which is used as condition in PyConditionalExpression as non-None
This commit is contained in:
Semyon Proshev
2016-11-25 19:10:02 +03:00
parent 54a5e386f4
commit a9ecefe927
3 changed files with 23 additions and 7 deletions
@@ -1504,6 +1504,16 @@ public class PyTypeTest extends PyTestCase {
"expr = foo(a=1, b=\"2\")");
}
// PY-21474
public void testReassigningOptionalListWithDefaultValue() {
doTest("Union[List[str], list]",
"def x(things):\n" +
" \"\"\"\n" +
" :type things: None | list[str]\n" +
" \"\"\"\n" +
" expr = things if things else []");
}
private static List<TypeEvalContext> getTypeEvalContexts(@NotNull PyExpression element) {
return ImmutableList.of(TypeEvalContext.codeAnalysis(element.getProject(), element.getContainingFile()).withTracing(),
TypeEvalContext.userInitiated(element.getProject(), element.getContainingFile()).withTracing());