src/eric7/Utilities/ClassBrowsers/pyclbr.py

branch
eric7
changeset 10216
c07a1ef5c5d3
parent 10050
3750abc45d5e
child 10433
328f3ec4b77a
diff -r d476667171a1 -r c07a1ef5c5d3 src/eric7/Utilities/ClassBrowsers/pyclbr.py
--- a/src/eric7/Utilities/ClassBrowsers/pyclbr.py	Tue Sep 26 18:26:21 2023 +0200
+++ b/src/eric7/Utilities/ClassBrowsers/pyclbr.py	Thu Sep 28 14:02:15 2023 +0200
@@ -10,6 +10,7 @@
 to find out the superclasses of a class as well as its attributes.
 """
 
+import keyword
 import re
 import sys
 
@@ -71,7 +72,7 @@
         (?P<MethodIndent> [ \t]* )
         (?: async [ \t]+ )? (?: cdef | cpdef | def) [ \t]+
         (?P<MethodName> \w+ )
-        (?: [ \t]* \[ (?: plain | html ) \] )?
+        (?: [ \t]* \[ [^\]]+ \] )?
         [ \t]* \(
         (?P<MethodSignature> (?: [^)] | \)[ \t]*,? )*? )
         \) [ \t]*
@@ -85,6 +86,7 @@
         (?: cdef [ \t]+ )?
         class [ \t]+
         (?P<ClassName> \w+ )
+        (?: [ \t]* \[ [^\]]+ \] )?
         [ \t]*
         (?P<ClassSupers> \( [^)]* \) )?
         [ \t]* :
@@ -95,6 +97,7 @@
         (?P<AttributeIndent> [ \t]* )
         self [ \t]* \. [ \t]*
         (?P<AttributeName> \w+ )
+        (?: [ \t]* : [^=\n]+ )?
         [ \t]* =
     )
 
@@ -105,6 +108,13 @@
         [ \t]* =
     )
 
+|   (?P<TypedVariable>
+        ^
+        (?P<TypedVariableIndent> [ \t]* )
+        (?P<TypedVariableName> \w+ )
+        [ \t]* :
+    )
+
 |   (?P<Main>
         ^
         if \s+ __name__ \s* == \s* [^:]+ : $
@@ -654,6 +664,36 @@
                             )
                         break
 
+        elif m.captured("TypedVariable"):
+            thisindent = _indent(m.captured("TypedVariableIndent"))
+            variable_name = m.captured("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 or not classstack:
+                    # global variable, reset class stack first
+                    classstack = []
+
+                    if "@@Globals@@" not in dictionary:
+                        dictionary["@@Globals@@"] = ClbrBaseClasses.ClbrBase(
+                            module, "Globals", file, lineno
+                        )
+                    dictionary["@@Globals@@"]._addglobal(
+                        Attribute(module, variable_name, file, lineno)
+                    )
+                else:
+                    index = -1
+                    while index >= -len(classstack):
+                        if classstack[index][1] >= thisindent:
+                            index -= 1
+                        else:
+                            if isinstance(classstack[index][0], Class):
+                                classstack[index][0]._addglobal(
+                                    Attribute(module, variable_name, file, lineno)
+                                )
+                            break
+
         elif m.captured("Publics"):
             idents = m.captured("Identifiers")
             lineno += src.count("\n", last_lineno_pos, start)

eric ide

mercurial