mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-76855 Do not report ambiguous access to a generic instance if the type parameter has a default
GitOrigin-RevId: ce6c1cb85beac3a326dd87c4477be8893d99e802
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c2b72108a3
commit
e52455d022
+3
-1
@@ -267,7 +267,9 @@ public class PyTypeCheckerInspection extends PyInspection {
|
||||
}
|
||||
|
||||
private static boolean requiresTypeSpecialization(@Nullable PyType type) {
|
||||
if (type instanceof PyTypeParameterType && !(type instanceof PySelfType)) return true;
|
||||
if (type instanceof PyTypeParameterType typeParameterType &&
|
||||
typeParameterType.getDefaultType() == null &&
|
||||
!(type instanceof PySelfType)) return true;
|
||||
return type instanceof PyCollectionType collectionType &&
|
||||
exists(collectionType.getElementTypes(), Visitor::requiresTypeSpecialization);
|
||||
}
|
||||
|
||||
@@ -2994,4 +2994,17 @@ def foo(param: str | int) -> TypeGuard[str]:
|
||||
v5: Hashable = DC5(0)
|
||||
""");
|
||||
}
|
||||
|
||||
// PY-76855
|
||||
public void testAccessToAttributeOfGenericClassWithDefaultIsNotAmbiguous() {
|
||||
doTestByText("""
|
||||
class Test1[T = int]():
|
||||
attr: T
|
||||
class Test2[T]():
|
||||
attr: T
|
||||
|
||||
Test1.attr #OK
|
||||
Test2.<warning descr="Access to generic instance variables via class is ambiguous">attr</warning>
|
||||
""");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user