diff -r b5808c3a9967 -r c8854a6300d1 src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Annotations/AnnotationsChecker.py --- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Annotations/AnnotationsChecker.py Tue May 30 17:25:17 2023 +0200 +++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Annotations/AnnotationsChecker.py Wed May 31 13:53:05 2023 +0200 @@ -53,6 +53,8 @@ ## Annotation Complexity "A891", "A892", + ## PEP 604 (use of typing.Union) + "A901", ] def __init__(self, source, filename, tree, select, ignore, expected, repeat, args): @@ -113,6 +115,7 @@ (self.__checkAnnotationsFuture, ("A871", "A872", "A873")), (self.__checkAnnotationsCoverage, ("A881",)), (self.__checkAnnotationComplexity, ("A891", "A892")), + (self.__checkAnnotationPep604, ("A901",)), ] self.__checkers = [] @@ -615,7 +618,7 @@ return annotationLength ####################################################################### - ## 'from __future__ import annotations' checck + ## 'from __future__ import annotations' check ## ## adapted from: flake8-future-annotations v1.1.0 ####################################################################### @@ -650,3 +653,21 @@ if checkFutureAnnotations and visitor.hasSimplifiedTypes(): simplifiedTypes = ", ".join(sorted(visitor.getSimplifiedTypes())) self.__error(0, 0, "A873", simplifiedTypes) + + ####################################################################### + ## check use of 'typing.Union' (see PEP 604) + ## + ## adapted from: flake8-pep604 v1.1.0 + ####################################################################### + + def __checkAnnotationPep604(self): + """ + Private method to check the use of typing.Union. + """ + from .AnnotationsUnionVisitor import AnnotationsUnionVisitor + + visitor = AnnotationsUnionVisitor() + visitor.visit(self.__tree) + + for node in visitor.getIssues(): + self.__error(node.lineno - 1, node.col_offset, "A901")