src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Annotations/AnnotationsChecker.py

branch
eric7
changeset 10058
5d965939ab85
parent 10050
3750abc45d5e
child 10086
c8854a6300d1
diff -r 1e31ca1078ab -r 5d965939ab85 src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Annotations/AnnotationsChecker.py
--- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Annotations/AnnotationsChecker.py	Tue May 23 14:39:14 2023 +0200
+++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Annotations/AnnotationsChecker.py	Tue May 23 15:58:50 2023 +0200
@@ -40,10 +40,10 @@
         "A204",
         "A205",
         "A206",
-        ## Mixed kind of annotations
-        "A301",
         ## Dynamically typed annotations
         "A401",
+        ## Type comments
+        "A402",
         ## Annotations Future
         "A871",
         "A872",
@@ -106,8 +106,8 @@
                     "A204",
                     "A205",
                     "A206",
-                    "A301",
                     "A401",
+                    "A402",
                 ),
             ),
             (self.__checkAnnotationsFuture, ("A871", "A872", "A873")),
@@ -186,7 +186,7 @@
     #######################################################################
     ## Annotations
     ##
-    ## adapted from: flake8-annotations v2.9.1
+    ## adapted from: flake8-annotations v3.0.1
     #######################################################################
 
     def __checkFunctionAnnotations(self):
@@ -240,6 +240,9 @@
 
         # Iterate over the arguments with missing type hints, by function.
         for function in visitor.functionDefinitions:
+            if function.hasTypeComment:
+                self.__error(function.lineno - 1, function.col_offset, "A402")
+
             if function.isDynamicallyTyped() and (
                 allowUntypedDefs or (function.isNested and allowUntypedNested)
             ):
@@ -253,32 +256,8 @@
             if function.hasDecorator(dispatchDecorators):
                 continue
 
-            # Create sentinels to check for mixed hint styles
-            hasTypeComment = function.hasTypeComment
-
-            has3107Annotation = False
-            # PEP 3107 annotations are captured by the return arg
-
+            # Iterate over the annotated args to look for opinionated warnings
             annotatedArgs = function.getAnnotatedArguments()
-
-            # Iterate over annotated args to detect mixing of type annotations
-            # and type comments. Emit this only once per function definition
-            for arg in annotatedArgs:
-                if arg.hasTypeComment:
-                    hasTypeComment = True
-
-                if arg.has3107Annotation:
-                    has3107Annotation = True
-
-                if hasTypeComment and has3107Annotation:
-                    # Short-circuit check for mixing of type comments &
-                    # 3107-style annotations
-                    self.__error(function.lineno - 1, function.col_offset, "A301")
-                    break
-
-            # Iterate over the annotated args to look for 'typing.Any' annotations
-            # We could combine this with the above loop but I'd rather not add even
-            # more sentinels unless we'd notice a significant enough performance impact
             for arg in annotatedArgs:
                 if arg.isDynamicallyTyped:
                     if allowStarArgAny and arg.annotationType in {
@@ -302,6 +281,11 @@
 
             # Record explicit errors for arguments that are missing annotations
             for arg in function.getMissedAnnotations():
+                # Check for type comments here since we're not considering them as
+                # typed args
+                if arg.hasTypeComment:
+                    self.__error(arg.lineno - 1, arg.col_offset, "A402")
+
                 if arg.argname == "return":
                     # return annotations have multiple possible short-circuit
                     # paths

eric ide

mercurial