diff --git a/python/src/com/jetbrains/python/psi/impl/PyClassImpl.java b/python/src/com/jetbrains/python/psi/impl/PyClassImpl.java index 561feda63191..27db8b6fe64b 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyClassImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyClassImpl.java @@ -1222,6 +1222,8 @@ public class PyClassImpl extends PyBaseElementImpl implements PyCla .map(PyWithItem::getTarget) .select(PyTargetExpression.class) .forEach(result::add); + + super.visitPyWithStatement(node); } }); return result; diff --git a/python/testData/inspections/PyUnresolvedReferencesInspection/instanceAttributeCreatedInsideWithStatement.py b/python/testData/inspections/PyUnresolvedReferencesInspection/instanceAttributeCreatedInsideWithStatement.py new file mode 100644 index 000000000000..fd25530a1870 --- /dev/null +++ b/python/testData/inspections/PyUnresolvedReferencesInspection/instanceAttributeCreatedInsideWithStatement.py @@ -0,0 +1,8 @@ +class Foo(object): + def __init__(self): + with open('b.py'): + self.scope = "a" + pass + + def get_scope(self): + return self.scope \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java index 807e879d85ef..0b4da8a34b8e 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java @@ -758,6 +758,11 @@ public class PyUnresolvedReferencesInspectionTest extends PyInspectionTestCase { assertNotParsed((PyFile)fooPsiFile); } + // PY-23164 + public void testInstanceAttributeCreatedInsideWithStatement() { + doTest(); + } + @NotNull @Override protected Class getInspectionClass() {