Sun, 26 Jun 2022 15:16:51 +0200
Changed edge column and max. line length pf code style checker to 88 characters because this gives better looking code (see 'Black' tool).
8773
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | |
8881
54e42bc2437a
Updated copyright for 2022.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8783
diff
changeset
|
3 | # Copyright (c) 2021 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
8773
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
4 | # |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
5 | |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | """ |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
7 | Module implementing a node visitor for function type annotations. |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
8 | """ |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
10 | # |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
11 | # The visitor and associated classes are adapted from flake8-future-annotations |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
12 | # v0.0.4 |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
13 | # |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
14 | |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
15 | import ast |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
16 | |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
17 | |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
18 | class AnnotationsFutureVisitor(ast.NodeVisitor): |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
19 | """ |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
20 | Class implementing a node visitor to check __future__ imports. |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
21 | """ |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
22 | SimplifyableTypes = ( |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
23 | "DefaultDict", |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
24 | "Deque", |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
25 | "Dict", |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
26 | "FrozenSet", |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
27 | "List", |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
28 | "Optional", |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
29 | "Set", |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
30 | "Tuple", |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
31 | "Union", |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
32 | "Type", |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
33 | ) |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
34 | |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
35 | def __init__(self): |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
36 | """ |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
37 | Constructor |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
38 | """ |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | super().__init__() |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
40 | |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
41 | self.__typingAliases = [] |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
42 | self.__importsFutureAnnotations = False |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
43 | |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
44 | # e.g. from typing import List, typing.List, t.List |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
45 | self.__typingImports = [] |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
46 | |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
47 | def visit_Import(self, node): |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
48 | """ |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
49 | Public method to check imports for typing related stuff. |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
50 | |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
51 | This looks like: |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
52 | import typing |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
53 | or |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
54 | import typing as t |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
55 | |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
56 | typing or t will be added to the list of typing aliases. |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
57 | |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
58 | @param node reference to the AST Import node |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
59 | @type ast.Import |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
60 | """ |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
61 | for alias in node.names: |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
62 | if alias.name == "typing": |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
63 | self.__typingAliases.append("typing") |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
64 | if alias.asname is not None: |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
65 | self.__typingAliases.append(alias.asname) |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
66 | |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
67 | self.generic_visit(node) |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
68 | |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
69 | def visit_ImportFrom(self, node): |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
70 | """ |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
71 | Public method to detect the 'from __future__ import annotations' |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
72 | import if present. |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
73 | |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
74 | If 'from typing import ...' is used, add simplifiable names that were |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
75 | imported. |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
76 | |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
77 | @param node reference to the AST ImportFrom node |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
78 | @type ast.ImportFrom |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
79 | """ |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
80 | if node.module == "__future__": |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
81 | for alias in node.names: |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
82 | if alias.name == "annotations": |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
83 | self.__importsFutureAnnotations = True |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
84 | |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
85 | if node.module == "typing": |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
86 | for alias in node.names: |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
87 | if alias.name in AnnotationsFutureVisitor.SimplifyableTypes: |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
88 | self.__typingImports.append(alias.name) |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
89 | |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
90 | self.generic_visit(node) |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
91 | |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
92 | def visit_Attribute(self, node): |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
93 | """ |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
94 | Public method to record simplifiable names. |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
95 | |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
96 | If 'import typing' or 'import typing as t' is used, add simplifiable |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
97 | names that were used later on in the code. |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
98 | |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
99 | @param node reference to the AST Attribute node |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
100 | @type ast.Attribute |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
101 | """ |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
102 | if ( |
8783
04fe1beecd9c
Fixed a few code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8773
diff
changeset
|
103 | node.attr in AnnotationsFutureVisitor.SimplifyableTypes and |
04fe1beecd9c
Fixed a few code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8773
diff
changeset
|
104 | isinstance(node.value, ast.Name) and |
04fe1beecd9c
Fixed a few code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8773
diff
changeset
|
105 | node.value.id in self.__typingAliases |
8773
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
106 | ): |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
107 | self.__typingImports.append(f"{node.value.id}.{node.attr}") |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
108 | |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
109 | self.generic_visit(node) |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
110 | |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
111 | def importsFutureAnnotations(self): |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
112 | """ |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
113 | Public method to check, if the analyzed code uses future annotation. |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
114 | |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
115 | @return flag indicatung the use of future annotation |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
116 | @rtype bool |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
117 | """ |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
118 | return self.__importsFutureAnnotations |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
119 | |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
120 | def hasTypingImports(self): |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
121 | """ |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
122 | Public method to check, if the analyzed code includes typing imports. |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
123 | |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
124 | @return flag indicating the use of typing imports |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
125 | @rtype bool |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
126 | """ |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
127 | return bool(self.__typingImports) |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
128 | |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
129 | def getTypingImports(self): |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
130 | """ |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
131 | Public method to get the list of typing imports. |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
132 | |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
133 | @return list of typing imports |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
134 | @rtype list of str |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
135 | """ |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
136 | return self.__typingImports[:] |