diff --git a/python/src/com/jetbrains/python/psi/types/PyTypeChecker.java b/python/src/com/jetbrains/python/psi/types/PyTypeChecker.java index 2a60dd6f54c4..0a315c4813a3 100644 --- a/python/src/com/jetbrains/python/psi/types/PyTypeChecker.java +++ b/python/src/com/jetbrains/python/psi/types/PyTypeChecker.java @@ -127,7 +127,11 @@ public class PyTypeChecker { return false; } if (expected instanceof PyUnionType) { - for (PyType t : ((PyUnionType)expected).getMembers()) { + final Collection expectedUnionTypeMembers = ((PyUnionType)expected).getMembers(); + final StreamEx notGenericTypes = StreamEx.of(expectedUnionTypeMembers).filter(type -> !PyGenericType.class.isInstance(type)); + final StreamEx genericTypes = StreamEx.of(expectedUnionTypeMembers).select(PyGenericType.class); + + for (PyType t : notGenericTypes.append(genericTypes)) { if (match(t, actual, context, substitutions, recursive)) { return true; } diff --git a/python/testSrc/com/jetbrains/python/PyTypeTest.java b/python/testSrc/com/jetbrains/python/PyTypeTest.java index 259eee353529..35f94842e56f 100644 --- a/python/testSrc/com/jetbrains/python/PyTypeTest.java +++ b/python/testSrc/com/jetbrains/python/PyTypeTest.java @@ -1398,6 +1398,13 @@ public class PyTypeTest extends PyTestCase { "expr = float.fromhex(\"0.5\")"); } + // PY-20409 + public void testGetFromDictWithDefaultNoneValue() { + doTest("Any", + "d = {}\n" + + "expr = d.get(\"abc\", None)"); + } + // PY-20757 public void testMinOrNone() { doTest("Union[None, Any]",