PY-28032 Optional[Any] in a type hint is not coerced into plain Any

This commit is contained in:
Mikhail Golubev
2018-02-20 15:04:01 +03:00
parent 6ddfb55e68
commit ca2017675f
2 changed files with 12 additions and 3 deletions
@@ -961,9 +961,9 @@ public class PyTypingTypeProvider extends PyTypeProviderBase {
if (operandNames.contains(OPTIONAL)) {
final PyExpression indexExpr = subscriptionExpr.getIndexExpression();
if (indexExpr != null) {
final PyType type = Ref.deref(getType(indexExpr, context));
if (type != null) {
return Ref.create(PyUnionType.union(type, PyNoneType.INSTANCE));
final Ref<PyType> typeRef = getType(indexExpr, context);
if (typeRef != null) {
return Ref.create(PyUnionType.union(typeRef.get(), PyNoneType.INSTANCE));
}
}
return Ref.create();
@@ -275,6 +275,15 @@ public class PyTypingTest extends PyTestCase {
" pass\n");
}
// PY-28032
public void testOptionalOfAny() {
doTest("Optional[Any]",
"from typing import Optional, Any\n" +
"\n" +
"x = None # type: Optional[Any]\n" +
"expr = x\n");
}
public void testOptionalFromDefaultNone() {
doTest("Optional[int]",
"def foo(expr: int = None):\n" +