mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-20744 Consider variable annotations only in current file to prevent unstabbing everywhere
It will be fixed eventually when we start storing annotations for parameter, functions and target expressions in stub files and process them using PyTypeParser only.
This commit is contained in:
@@ -176,14 +176,16 @@ public class PyTypingTypeProvider extends PyTypeProviderBase {
|
||||
public PyType getReferenceType(@NotNull PsiElement referenceTarget, TypeEvalContext context, @Nullable PsiElement anchor) {
|
||||
if (referenceTarget instanceof PyTargetExpression) {
|
||||
final PyTargetExpression target = (PyTargetExpression)referenceTarget;
|
||||
// XXX: Requires switching from stub to AST
|
||||
final PyAnnotation annotation = target.getAnnotation();
|
||||
if (annotation != null) {
|
||||
final PyExpression value = annotation.getValue();
|
||||
if (value != null) {
|
||||
return getType(value, new Context(context));
|
||||
if (context.maySwitchToAST(target)) {
|
||||
// XXX: Requires switching from stub to AST
|
||||
final PyAnnotation annotation = target.getAnnotation();
|
||||
if (annotation != null) {
|
||||
final PyExpression value = annotation.getValue();
|
||||
if (value != null) {
|
||||
return getType(value, new Context(context));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
final String comment = target.getTypeCommentAnnotation();
|
||||
if (comment != null) {
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
attr: int = ...
|
||||
@@ -0,0 +1,3 @@
|
||||
from .lib import attr
|
||||
|
||||
x = attr
|
||||
@@ -596,4 +596,17 @@ public class PyStubsTest extends PyTestCase {
|
||||
assertNotParsed(file1);
|
||||
assertNotParsed(file2);
|
||||
}
|
||||
|
||||
public void testVariableAnnotationsInExternalFiles() {
|
||||
runWithLanguageLevel(LanguageLevel.PYTHON36, () -> {
|
||||
final PyFile current = getTestFile(getTestName(true) + "/main.py");
|
||||
final PyFile external = getTestFile(getTestName(true) + "/lib.py");
|
||||
final PyTargetExpression attr = current.findTopLevelAttribute("x");
|
||||
assertNotNull(attr);
|
||||
final TypeEvalContext context = TypeEvalContext.codeAnalysis(myFixture.getProject(), current);
|
||||
// Will turn into concrete type when we start saving annotations in stubs
|
||||
assertNull(context.getType(attr));
|
||||
assertNotParsed(external);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user