Tue, 18 Oct 2022 16:06:21 +0200
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
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 |
9276
e6748a5e24b9
Code Style Checker
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
12 | # v0.0.5 |
8773
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 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
22 | |
8773
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
23 | SimplifyableTypes = ( |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
24 | "DefaultDict", |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
25 | "Deque", |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
26 | "Dict", |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
27 | "FrozenSet", |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
28 | "List", |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
29 | "Optional", |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
30 | "Set", |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
31 | "Tuple", |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
32 | "Union", |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
33 | "Type", |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
34 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
35 | |
8773
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
36 | 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
|
37 | """ |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
38 | Constructor |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | """ |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
40 | super().__init__() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
41 | |
8773
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
42 | self.__typingAliases = [] |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
43 | self.__importsFutureAnnotations = False |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
44 | |
8773
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
45 | # 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
|
46 | self.__typingImports = [] |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
47 | |
8773
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
48 | 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
|
49 | """ |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
50 | Public method to check imports for typing related stuff. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
51 | |
8773
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
52 | 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
|
53 | import typing |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
54 | or |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
55 | import typing as t |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
56 | |
8773
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
57 | typing or t will be added to the list of typing aliases. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
58 | |
8773
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
59 | @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
|
60 | @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
|
61 | """ |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
62 | 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
|
63 | 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
|
64 | 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
|
65 | 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
|
66 | self.__typingAliases.append(alias.asname) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
67 | |
8773
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
68 | self.generic_visit(node) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
69 | |
8773
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
70 | 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
|
71 | """ |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
72 | 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
|
73 | 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
|
74 | |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
75 | 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
|
76 | imported. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
77 | |
8773
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
78 | @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
|
79 | @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
|
80 | """ |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
81 | 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
|
82 | 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
|
83 | 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
|
84 | 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
|
85 | |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
86 | 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
|
87 | 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
|
88 | 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
|
89 | 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
|
90 | |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
91 | self.generic_visit(node) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
92 | |
8773
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
93 | 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
|
94 | """ |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
95 | Public method to record simplifiable names. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
96 | |
8773
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
97 | 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
|
98 | names that were used later on in the code. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
99 | |
8773
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
100 | @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
|
101 | @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
|
102 | """ |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
103 | if ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
104 | node.attr in AnnotationsFutureVisitor.SimplifyableTypes |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
105 | and isinstance(node.value, ast.Name) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
106 | and 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
|
107 | ): |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
108 | self.__typingImports.append(f"{node.value.id}.{node.attr}") |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
109 | |
8773
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
110 | self.generic_visit(node) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
111 | |
8773
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
112 | 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
|
113 | """ |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
114 | Public method to check, if the analyzed code uses future annotation. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
115 | |
8773
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
116 | @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
|
117 | @rtype bool |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
118 | """ |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
119 | return self.__importsFutureAnnotations |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
120 | |
8773
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
121 | 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
|
122 | """ |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
123 | Public method to check, if the analyzed code includes typing imports. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
124 | |
8773
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
125 | @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
|
126 | @rtype bool |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
127 | """ |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
128 | return bool(self.__typingImports) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
129 | |
8773
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
130 | 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
|
131 | """ |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
132 | Public method to get the list of typing imports. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
133 | |
8773
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
134 | @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
|
135 | @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
|
136 | """ |
3dd81b827455
Extended the annotations checker to check for missing 'from __future__ import annotations'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
137 | return self.__typingImports[:] |