mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-21175 If type assertion excludes a type from Any, leave Any as the result
This commit is contained in:
+1
-1
@@ -167,7 +167,7 @@ public class PyTypeAssertionEvaluator extends PyRecursiveElementVisitor {
|
||||
else if (initial instanceof PyUnionType) {
|
||||
return Ref.create(((PyUnionType)initial).exclude(transformedType, context));
|
||||
}
|
||||
else if (PyTypeChecker.match(transformedType, initial, context)) {
|
||||
else if (initial != null && PyTypeChecker.match(transformedType, initial, context)) {
|
||||
return null;
|
||||
}
|
||||
return Ref.create(initial);
|
||||
|
||||
@@ -2012,6 +2012,26 @@ public class PyTypeTest extends PyTestCase {
|
||||
" expr = var");
|
||||
}
|
||||
|
||||
// PY-21626
|
||||
public void testNestedConflictingIsNoneChecksInitialAny() {
|
||||
doTest("Optional[Any]",
|
||||
"def f(x):\n" +
|
||||
" if x is None:\n" +
|
||||
" if x is not None:\n" +
|
||||
" pass\n" +
|
||||
" expr = x");
|
||||
}
|
||||
|
||||
// PY-21626
|
||||
public void testNestedConflictingIsNoneChecksInitialKnown() {
|
||||
doTest("Optional[str]",
|
||||
"x = 'foo'\n" +
|
||||
"if x is None:\n" +
|
||||
" if x is not None:\n" +
|
||||
" pass\n" +
|
||||
"expr = x");
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
Reference in New Issue
Block a user