PY-20364 Fixed: Hinting does not support basestring in open()

Replace actual basestring type with union of str and unicode while matching types in PyTypeChecker
This commit is contained in:
Semyon Proshev
2016-10-24 17:37:20 +03:00
parent 1b3872e12b
commit a0c3bdf922
4 changed files with 20 additions and 1 deletions
@@ -395,7 +395,8 @@ public class PyBuiltinCache {
}
}
private PyType getStrOrUnicodeType() {
@Nullable
public PyType getStrOrUnicodeType() {
return PyUnionType.union(getObjectType("str"), getObjectType("unicode"));
}
@@ -61,6 +61,14 @@ public class PyTypeChecker {
private static boolean match(@Nullable PyType expected, @Nullable PyType actual, @NotNull TypeEvalContext context,
@Nullable Map<PyGenericType, PyType> substitutions, boolean recursive) {
// TODO: subscriptable types?, module types?, etc.
if (actual instanceof PyClassType) {
final PyClassType classType = (PyClassType)actual;
final PyBuiltinCache builtinCache = PyBuiltinCache.getInstance(classType.getPyClass());
if (actual == builtinCache.getObjectType(PyNames.BASESTRING)) {
return match(expected, builtinCache.getStrOrUnicodeType(), context, substitutions, recursive);
}
}
if (expected instanceof PyGenericType && substitutions != null) {
final PyGenericType generic = (PyGenericType)expected;
final PyType subst = substitutions.get(generic);
@@ -0,0 +1,5 @@
def hello(filename):
"""
:type filename: basestring
"""
open(filename)
@@ -331,4 +331,9 @@ public class PyTypeCheckerInspectionTest extends PyTestCase {
public void testCsvRegisterDialect() {
doMultiFileTest();
}
// PY-20364
public void testActualBasestringExpectedUnionStrUnicode() {
doTest();
}
}