From 59003c00bef133f1d9f45e80025554fc83bd19e9 Mon Sep 17 00:00:00 2001 From: Fabio Zadrozny Date: Sun, 3 Sep 2023 09:28:04 -0300 Subject: [PATCH] wip --- .github/workflows/release-pydev.yml | 2 +- .../AbstractScopeAnalyzerVisitor.java | 16 ++++++++++++++++ .../analysis/visitors/OccurrencesVisitor.java | 7 ++++++- .../python/pydev/analysis/visitors/Scope.java | 14 ++++++++++++++ .../pydev/core/TestDependent.github.properties | 4 ++-- .../analysis/OccurrencesAnalyzerPy310Test.java | 18 ++++++++++++++++++ 6 files changed, 57 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release-pydev.yml b/.github/workflows/release-pydev.yml index d7893985fd..0ee55d7834 100644 --- a/.github/workflows/release-pydev.yml +++ b/.github/workflows/release-pydev.yml @@ -46,7 +46,7 @@ jobs: which java which mvn echo ---- rt.jar should be listed below - find /opt/hostedtoolcache/Java_Adopt_jdk/11.0.19-7/x64/ -name "*.jar" + find /opt/hostedtoolcache/Java_Adopt_jdk/11.0.20-101/x64/ -name "*.jar" - name: xvfb shell: bash diff --git a/plugins/com.python.pydev.analysis/src/com/python/pydev/analysis/scopeanalysis/AbstractScopeAnalyzerVisitor.java b/plugins/com.python.pydev.analysis/src/com/python/pydev/analysis/scopeanalysis/AbstractScopeAnalyzerVisitor.java index d1a7ff741d..7e862539cc 100644 --- a/plugins/com.python.pydev.analysis/src/com/python/pydev/analysis/scopeanalysis/AbstractScopeAnalyzerVisitor.java +++ b/plugins/com.python.pydev.analysis/src/com/python/pydev/analysis/scopeanalysis/AbstractScopeAnalyzerVisitor.java @@ -69,7 +69,9 @@ import org.python.pydev.parser.jython.ast.decoratorsType; import org.python.pydev.parser.jython.ast.exprType; import org.python.pydev.parser.visitors.NodeUtils; +import org.python.pydev.shared_core.model.ISimpleNode; import org.python.pydev.shared_core.string.FullRepIterable; +import org.python.pydev.shared_core.structure.FastStack; import org.python.pydev.shared_core.structure.StringToIntCounterSmallSet; import com.python.pydev.analysis.visitors.Found; @@ -1213,6 +1215,20 @@ protected boolean markRead(IToken token, String rep, boolean addToNotDefined, bo } } + if (!found) { + if (this.scope.isVisitingStrTypeAnnotation()) { + FastStack scopeStack = this.currentLocalScope.getScopeStack(); + for (ISimpleNode n : scopeStack) { + if (n instanceof ClassDef) { + ClassDef classDef = (ClassDef) n; + if (rep.equals(((NameTok) classDef.name).id)) { + found = true; + break; + } + } + } + } + } if (!found) { //this token might not be defined... (still, might be in names to ignore) int i; diff --git a/plugins/com.python.pydev.analysis/src/com/python/pydev/analysis/visitors/OccurrencesVisitor.java b/plugins/com.python.pydev.analysis/src/com/python/pydev/analysis/visitors/OccurrencesVisitor.java index 286d5bed96..1be681dddc 100644 --- a/plugins/com.python.pydev.analysis/src/com/python/pydev/analysis/visitors/OccurrencesVisitor.java +++ b/plugins/com.python.pydev.analysis/src/com/python/pydev/analysis/visitors/OccurrencesVisitor.java @@ -261,7 +261,12 @@ public Object visitStr(Str node) throws Exception { if (errorOnParsing == null) { new FixLinesVisitor(node.beginLine - 1, node.beginColumn + startInternalStrColOffset - 1) .traverse(typingNode); - this.traverse(typingNode); + this.scope.startVisitingStrTypeAnnotation(); + try { + this.traverse(typingNode); + } finally { + this.scope.endVisitingStrTypeAnnotation(); + } } } catch (Exception e) { if (errorOnParsing == null) { diff --git a/plugins/com.python.pydev.analysis/src/com/python/pydev/analysis/visitors/Scope.java b/plugins/com.python.pydev.analysis/src/com/python/pydev/analysis/visitors/Scope.java index 627800bd6e..27881ff412 100644 --- a/plugins/com.python.pydev.analysis/src/com/python/pydev/analysis/visitors/Scope.java +++ b/plugins/com.python.pydev.analysis/src/com/python/pydev/analysis/visitors/Scope.java @@ -450,4 +450,18 @@ public ScopeItems getPrevScopeItems() { return scope.get(scope.size() - 2); } + private int visitingStrTypeAnnotation = 0; + + public void startVisitingStrTypeAnnotation() { + visitingStrTypeAnnotation += 1; + } + + public void endVisitingStrTypeAnnotation() { + visitingStrTypeAnnotation -= 1; + } + + public boolean isVisitingStrTypeAnnotation() { + return visitingStrTypeAnnotation > 0; + } + } diff --git a/plugins/org.python.pydev.core/tests/org/python/pydev/core/TestDependent.github.properties b/plugins/org.python.pydev.core/tests/org/python/pydev/core/TestDependent.github.properties index 2747676897..9fafe0c21f 100644 --- a/plugins/org.python.pydev.core/tests/org/python/pydev/core/TestDependent.github.properties +++ b/plugins/org.python.pydev.core/tests/org/python/pydev/core/TestDependent.github.properties @@ -19,8 +19,8 @@ TEST_PYDEV_BASE_LOC=/home/runner/work/Pydev/Pydev/plugins/ PYTHON_LIB=/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/ #java info -JAVA_LOCATION=/opt/hostedtoolcache/Java_Adopt_jdk/11.0.20-8/x64/bin/java -JAVA_RT_JAR_LOCATION=/opt/hostedtoolcache/Java_Adopt_jdk/11.0.20-8/x64/lib/rt.jar +JAVA_LOCATION=/opt/hostedtoolcache/Java_Adopt_jdk/11.0.20-101/x64/bin/java +JAVA_RT_JAR_LOCATION=/opt/hostedtoolcache/Java_Adopt_jdk/11.0.20-101/x64/lib/rt.jar #Jython JYTHON_JAR_LOCATION=/home/runner/work/Pydev/jython_install_dir/jython.jar diff --git a/plugins/org.python.pydev/tests_analysis/com/python/pydev/analysis/OccurrencesAnalyzerPy310Test.java b/plugins/org.python.pydev/tests_analysis/com/python/pydev/analysis/OccurrencesAnalyzerPy310Test.java index 9e9048e3a1..396f417ad9 100644 --- a/plugins/org.python.pydev/tests_analysis/com/python/pydev/analysis/OccurrencesAnalyzerPy310Test.java +++ b/plugins/org.python.pydev/tests_analysis/com/python/pydev/analysis/OccurrencesAnalyzerPy310Test.java @@ -561,6 +561,24 @@ public void testTypingInfoInStr() { checkNoError(); } + public void testTypingInfoInStrOk() { + doc = new Document("class MyClass:\n" + + " def method(self, a: \"MyClass\"):\n" + + " pass"); + checkNoError(); + } + + public void testTypingInfoInStrOk2() { + doc = new Document("" + + "" + + "def method(a: 'MyClass'):\n" + + " pass\n" + + "class MyClass:\n" + + " pass" + + ""); + checkNoError(); + } + public void testTypingInfoInStrBad() { doc = new Document("\n" + "a: 'Hashable'\n"