mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
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:
@@ -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);
|
||||
|
||||
+5
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user