src/eric7/Utilities/ClassBrowsers/pyclbr.py

branch
eric7
changeset 10477
11b5d533e4a2
parent 10471
28d4780d6a66
child 10592
2bada76be1a6
child 10677
6ee2e475490c
diff -r 5182a7c5a9f3 -r 11b5d533e4a2 src/eric7/Utilities/ClassBrowsers/pyclbr.py
--- a/src/eric7/Utilities/ClassBrowsers/pyclbr.py	Thu Jan 04 10:43:29 2024 +0100
+++ b/src/eric7/Utilities/ClassBrowsers/pyclbr.py	Thu Jan 04 17:07:38 2024 +0100
@@ -71,7 +71,7 @@
         ^
         (?P<MethodIndent> [ \t]* )
         (?: async [ \t]+ )? (?: cdef | cpdef | def) [ \t]+
-        (?P<MethodName> \w+ )
+        (?P<MethodName> [\pL_] \w* )
         (?: [ \t]* \[ [^\]]+ \] )?
         [ \t]* \(
         (?P<MethodSignature> (?: [^)] | \)[ \t]*,? )*? )
@@ -85,7 +85,7 @@
         (?P<ClassIndent> [ \t]* )
         (?: cdef [ \t]+ )?
         class [ \t]+
-        (?P<ClassName> \w+ )
+        (?P<ClassName> [\pL_] \w* )
         (?: [ \t]* \[ [^\]]+ \] )?
         [ \t]*
         (?P<ClassSupers> \( [^)]* \) )?
@@ -96,22 +96,29 @@
         ^
         (?P<AttributeIndent> [ \t]* )
         self [ \t]* \. [ \t]*
-        (?P<AttributeName> \w+ )
-        (?: [ \t]* : [^=\n]+ )?
+        (?P<AttributeName> [\pL_] \w* )
         [ \t]* =
     )
 
+|   (?P<TypedAttribute>
+        ^
+        (?P<TypedAttributeIndent> [ \t]* )
+        self [ \t]* \. [ \t]*
+        (?P<TypedAttributeName> [\pL_] \w* )
+        [ \t]* : [ \t]+
+    )
+
 |   (?P<Variable>
         ^
         (?P<VariableIndent> [ \t]* )
-        (?P<VariableName> \w+ )
+        (?P<VariableName> [\pL_] \w* )
         [ \t]* =
     )
 
 |   (?P<TypedVariable>
         ^
         (?P<TypedVariableIndent> [ \t]* )
-        (?P<TypedVariableName> \w+ )
+        (?P<TypedVariableName> [\pL_] \w* )
         [ \t]* :
     )
 
@@ -646,7 +653,11 @@
                 classstack[-1][0]._addclass(class_name, cur_class)
             classstack.append((cur_class, thisindent))
 
-        elif m.captured("Attribute"):
+        elif m.captured("Attribute") or m.captured("TypedAttribute"):
+            if m.captured("Attribute"):
+                attribute_name = m.captured("AttributeName")
+            else:
+                attribute_name = m.captured("TypedAttributeName")
             lineno += src.count("\n", last_lineno_pos, start)
             last_lineno_pos = start
             index = -1
@@ -654,7 +665,7 @@
                 if classstack[index][0] is not None and not isinstance(
                     classstack[index][0], Function
                 ):
-                    attr = Attribute(module, m.captured("AttributeName"), file, lineno)
+                    attr = Attribute(module, attribute_name, file, lineno)
                     classstack[index][0]._addattribute(attr)
                     break
                 else:
@@ -666,9 +677,16 @@
             last_lineno_pos = start
             classstack = []
 
-        elif m.captured("Variable"):
-            thisindent = _indent(m.captured("VariableIndent"))
-            variable_name = m.captured("VariableName")
+        elif m.captured("Variable") or m.captured("TypedVariable"):
+            if m.captured("Variable"):
+                thisindent = _indent(m.captured("VariableIndent"))
+                variable_name = m.captured("VariableName")
+            else:
+                thisindent = _indent(m.captured("TypedVariableIndent"))
+                variable_name = m.captured("TypedVariableName")
+                if keyword.iskeyword(variable_name):
+                    # only if the determined name is not a keyword (e.g. else, except)
+                    continue
             lineno += src.count("\n", last_lineno_pos, start)
             last_lineno_pos = start
             if thisindent == 0 or not classstack:
@@ -698,40 +716,6 @@
                             )
                         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)
-                                )
-                            elif isinstance(classstack[index][0], Function):
-                                classstack[index][0]._addattribute(
-                                    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