51 ## Annotation Coverage |
51 ## Annotation Coverage |
52 "A881", |
52 "A881", |
53 ## Annotation Complexity |
53 ## Annotation Complexity |
54 "A891", |
54 "A891", |
55 "A892", |
55 "A892", |
|
56 ## PEP 604 (use of typing.Union) |
|
57 "A901", |
56 ] |
58 ] |
57 |
59 |
58 def __init__(self, source, filename, tree, select, ignore, expected, repeat, args): |
60 def __init__(self, source, filename, tree, select, ignore, expected, repeat, args): |
59 """ |
61 """ |
60 Constructor |
62 Constructor |
111 ), |
113 ), |
112 ), |
114 ), |
113 (self.__checkAnnotationsFuture, ("A871", "A872", "A873")), |
115 (self.__checkAnnotationsFuture, ("A871", "A872", "A873")), |
114 (self.__checkAnnotationsCoverage, ("A881",)), |
116 (self.__checkAnnotationsCoverage, ("A881",)), |
115 (self.__checkAnnotationComplexity, ("A891", "A892")), |
117 (self.__checkAnnotationComplexity, ("A891", "A892")), |
|
118 (self.__checkAnnotationPep604, ("A901",)), |
116 ] |
119 ] |
117 |
120 |
118 self.__checkers = [] |
121 self.__checkers = [] |
119 for checker, codes in checkersWithCodes: |
122 for checker, codes in checkersWithCodes: |
120 if any(not (code and self.__ignoreCode(code)) for code in codes): |
123 if any(not (code and self.__ignoreCode(code)) for code in codes): |
613 ) |
616 ) |
614 |
617 |
615 return annotationLength |
618 return annotationLength |
616 |
619 |
617 ####################################################################### |
620 ####################################################################### |
618 ## 'from __future__ import annotations' checck |
621 ## 'from __future__ import annotations' check |
619 ## |
622 ## |
620 ## adapted from: flake8-future-annotations v1.1.0 |
623 ## adapted from: flake8-future-annotations v1.1.0 |
621 ####################################################################### |
624 ####################################################################### |
622 |
625 |
623 def __checkAnnotationsFuture(self): |
626 def __checkAnnotationsFuture(self): |
648 self.__error(0, 0, "A872") |
651 self.__error(0, 0, "A872") |
649 |
652 |
650 if checkFutureAnnotations and visitor.hasSimplifiedTypes(): |
653 if checkFutureAnnotations and visitor.hasSimplifiedTypes(): |
651 simplifiedTypes = ", ".join(sorted(visitor.getSimplifiedTypes())) |
654 simplifiedTypes = ", ".join(sorted(visitor.getSimplifiedTypes())) |
652 self.__error(0, 0, "A873", simplifiedTypes) |
655 self.__error(0, 0, "A873", simplifiedTypes) |
|
656 |
|
657 ####################################################################### |
|
658 ## check use of 'typing.Union' (see PEP 604) |
|
659 ## |
|
660 ## adapted from: flake8-pep604 v1.1.0 |
|
661 ####################################################################### |
|
662 |
|
663 def __checkAnnotationPep604(self): |
|
664 """ |
|
665 Private method to check the use of typing.Union. |
|
666 """ |
|
667 from .AnnotationsUnionVisitor import AnnotationsUnionVisitor |
|
668 |
|
669 visitor = AnnotationsUnionVisitor() |
|
670 visitor.visit(self.__tree) |
|
671 |
|
672 for node in visitor.getIssues(): |
|
673 self.__error(node.lineno - 1, node.col_offset, "A901") |