mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-26947 Class variable mistaken as module global variable
Prevent resolving class-level target expressions in global scope. Merge-request: IJ-MR-155098 Merged-by: Aleksandr Govenko <aleksandr.govenko@jetbrains.com> GitOrigin-RevId: 2452801387ee2480e61b2f5119e7f3f2704cb4ef
This commit is contained in:
committed by
intellij-monorepo-bot
parent
ab83df801d
commit
0c54074d30
@@ -1419,6 +1419,15 @@ public abstract class PyCommonResolveTest extends PyCommonResolveTestCase {
|
||||
assertEquals("global", ((PyStringLiteralExpression)value).getStringValue());
|
||||
}
|
||||
|
||||
// PY-26947
|
||||
public void testVariableDeclaredOnClassLevelResolvesOnlyToItself() {
|
||||
final PyTargetExpression foo = assertResolvesTo(PyTargetExpression.class, "foo");
|
||||
|
||||
final PyExpression value = foo.findAssignedValue();
|
||||
assertInstanceOf(value, PyStringLiteralExpression.class);
|
||||
assertEquals("correct", ((PyStringLiteralExpression)value).getStringValue());
|
||||
}
|
||||
|
||||
// PY-29975
|
||||
public void testUnboundVariableOnClassLevelNotDeclaredBelow() {
|
||||
assertResolvesTo(PyNamedParameter.class, "foo");
|
||||
|
||||
+1
-1
@@ -256,7 +256,7 @@ public class PyReferenceImpl implements PsiReferenceEx, PsiPolyVariantReference
|
||||
})
|
||||
.toImmutableList();
|
||||
}
|
||||
else if (resolvedOwner instanceof PyClass) {
|
||||
else if (resolvedOwner instanceof PyClass && !(referenceAnchor instanceof PyTargetExpression)) {
|
||||
resolveInParentScope = () -> PyResolveUtil.parentScopeForUnresolvedClassLevelName((PyClass)resolvedOwner, referencedName);
|
||||
}
|
||||
else if (instructions.isEmpty() && allInOwnScopeComprehensions(resolvedElements)) {
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
foo = 'incorrect'
|
||||
|
||||
class A:
|
||||
foo = 'correct'
|
||||
# <ref>
|
||||
Reference in New Issue
Block a user