12
12
13
13
import ast
14
14
import re
15
- from typing import Any
15
+ from typing import TYPE_CHECKING , Any
16
16
17
17
from .flake8triovisitor import Flake8TrioVisitor
18
18
from .helpers import error_class , fnmatch_qualified_name , get_matching_call
19
19
20
+ if TYPE_CHECKING :
21
+ from collections .abc import Mapping
22
+
20
23
21
24
@error_class
22
25
class Visitor200 (Flake8TrioVisitor ):
23
- error_codes = {
26
+ error_codes : Mapping [ str , str ] = {
24
27
"TRIO200" : (
25
28
"User-configured blocking sync call {0} in async function, consider "
26
29
"replacing with {1}."
@@ -55,7 +58,7 @@ def visit_blocking_call(self, node: ast.Call):
55
58
56
59
@error_class
57
60
class Visitor21X (Visitor200 ):
58
- error_codes = {
61
+ error_codes : Mapping [ str , str ] = {
59
62
"TRIO210" : "Sync HTTP call {} in async function, use `httpx.AsyncClient`." ,
60
63
"TRIO211" : (
61
64
"Likely sync HTTP call {} in async function, use `httpx.AsyncClient`."
@@ -114,7 +117,7 @@ def visit_blocking_call(self, node: ast.Call):
114
117
115
118
@error_class
116
119
class Visitor212 (Visitor200 ):
117
- error_codes = {
120
+ error_codes : Mapping [ str , str ] = {
118
121
"TRIO212" : (
119
122
"Blocking sync HTTP call {1} on httpx object {0}, use httpx.AsyncClient."
120
123
)
@@ -166,7 +169,7 @@ def visit_blocking_call(self, node: ast.Call):
166
169
# Process invocations 202
167
170
@error_class
168
171
class Visitor22X (Visitor200 ):
169
- error_codes = {
172
+ error_codes : Mapping [ str , str ] = {
170
173
"TRIO220" : (
171
174
"Sync call {} in async function, use "
172
175
"`await nursery.start({}.run_process, ...)`."
@@ -225,7 +228,7 @@ def is_p_wait(arg: ast.expr) -> bool:
225
228
226
229
@error_class
227
230
class Visitor23X (Visitor200 ):
228
- error_codes = {
231
+ error_codes : Mapping [ str , str ] = {
229
232
"TRIO230" : "Sync call {0} in async function, use `{1}.open_file(...)`." ,
230
233
"TRIO231" : "Sync call {0} in async function, use `{1}.wrap_file({0})`." ,
231
234
}
@@ -251,7 +254,7 @@ def visit_blocking_call(self, node: ast.Call):
251
254
252
255
@error_class
253
256
class Visitor232 (Visitor200 ):
254
- error_codes = {
257
+ error_codes : Mapping [ str , str ] = {
255
258
"TRIO232" : (
256
259
"Blocking sync call {1} on file object {0}, wrap the file object"
257
260
"in `{2}.wrap_file()` to get an async file object."
@@ -281,7 +284,7 @@ def visit_blocking_call(self, node: ast.Call):
281
284
282
285
@error_class
283
286
class Visitor24X (Visitor200 ):
284
- error_codes = {
287
+ error_codes : Mapping [ str , str ] = {
285
288
"TRIO240" : "Avoid using os.path, prefer using {1}.Path objects." ,
286
289
}
287
290
0 commit comments