mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-28032 Optional[Any] in a type hint is not coerced into plain Any
This commit is contained in:
@@ -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" +
|
||||
|
||||
Reference in New Issue
Block a user