src/eric7/Utilities/ModuleParser.py

branch
eric7
changeset 10216
c07a1ef5c5d3
parent 10180
3a595df36c9a
child 10258
e7764f992a01
--- a/src/eric7/Utilities/ModuleParser.py	Tue Sep 26 18:26:21 2023 +0200
+++ b/src/eric7/Utilities/ModuleParser.py	Thu Sep 28 14:02:15 2023 +0200
@@ -16,6 +16,7 @@
 
 import contextlib
 import importlib.machinery
+import keyword
 import os
 import re
 import sys
@@ -68,7 +69,7 @@
     (?P<Comment>
         \# .*? $   # ignore everything in comments
     )
-    
+
 |   (?P<String>
         \""" (?P<StringContents1>
                [^"\\]* (?:
@@ -145,7 +146,7 @@
         (?P<MethodIndent> [ \t]* )
         (?: async [ \t]+ )? (?: cdef | cpdef | def) [ \t]+
         (?P<MethodName> \w+ )
-        (?: [ \t]* \[ (?: plain | html ) \] )?
+        (?: [ \t]* \[ [^\]]+ \] )?
         [ \t]* \(
         (?P<MethodSignature> (?: [^)] | \)[ \t]*,? )*? )
         \) [ \t]*
@@ -159,6 +160,7 @@
         (?: cdef [ \t]+ )?
         class [ \t]+
         (?P<ClassName> \w+ )
+        (?: [ \t]* \[ [^\]]+ \] )?
         [ \t]*
         (?P<ClassSupers> \( [^)]* \) )?
         [ \t]* :
@@ -169,6 +171,7 @@
         (?P<AttributeIndent> [ \t]* )
         self [ \t]* \. [ \t]*
         (?P<AttributeName> \w+ )
+        (?: [ \t]* : [^=\n]+ )?
         [ \t]* =
     )
 
@@ -179,6 +182,13 @@
         [ \t]* = [ \t]* (?P<VariableSignal> (?:pyqtSignal)? )
     )
 
+|   (?P<TypedVariable>
+        ^
+        (?P<TypedVariableIndent> [ \t]* )
+        (?P<TypedVariableName> \w+ )
+        [ \t]* :
+    )
+
 |   (?P<Main>
         ^
         if \s+ __name__ \s* == \s* [^:]+ : $
@@ -839,6 +849,34 @@
                                 classstack[index][0].addGlobal(variable_name, attr)
                             break
 
+            elif m.start("TypedVariable") >= 0:
+                thisindent = _indent(m.group("TypedVariableIndent"))
+                variable_name = m.group("TypedVariableName")
+                if not keyword.iskeyword(variable_name):
+                    # only if the determined name is not a keyword (e.g. else, except)
+                    lineno += src.count("\n", last_lineno_pos, start)
+                    last_lineno_pos = start
+                    if thisindent == 0:
+                        # global variable
+                        attr = Attribute(self.name, variable_name, self.file, lineno)
+                        self.__py_setVisibility(attr)
+                        self.addGlobal(variable_name, attr)
+                    else:
+                        index = -1
+                        while index >= -len(classstack):
+                            if classstack[index][1] >= thisindent:
+                                index -= 1
+                            else:
+                                if classstack[index][0] is not None and isinstance(
+                                    classstack[index][0], Class
+                                ):
+                                    attr = Attribute(
+                                        self.name, variable_name, self.file, lineno
+                                    )
+                                    self.__py_setVisibility(attr)
+                                    classstack[index][0].addGlobal(variable_name, attr)
+                                break
+
             elif m.start("Import") >= 0:
                 # - import module
                 names = [

eric ide

mercurial