Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Sep 3, 2023
1 parent ba5f4f0 commit 59003c0
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-pydev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1213,6 +1215,20 @@ protected boolean markRead(IToken token, String rep, boolean addToNotDefined, bo
}
}

if (!found) {
if (this.scope.isVisitingStrTypeAnnotation()) {
FastStack<ISimpleNode> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 59003c0

Please sign in to comment.