Skip to content

Commit 26d089b

Browse files
committed
Use constants for TYPE_CHECKING
1 parent 794743b commit 26d089b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

ariadne_codegen/contrib/no_global_imports.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
from ariadne_codegen import Plugin
1717

18+
TYPE_CHECKING_MODULE: str = "typing"
19+
TYPE_CHECKING_FLAG: str = "TYPE_CHECKING"
20+
1821

1922
class NoGlobalImportsPlugin(Plugin):
2023
"""Only import types when you call an endpoint needing it"""
@@ -313,7 +316,7 @@ def _update_imports(self, module: ast.Module) -> ast.Name | None:
313316
type_checking_imports[module_name].names.append(ast.alias(cls))
314317

315318
import_if_type_checking = ast.If(
316-
test=ast.Name(id="TYPE_CHECKING"),
319+
test=ast.Name(id=TYPE_CHECKING_FLAG),
317320
body=list(type_checking_imports.values()),
318321
orelse=[],
319322
)
@@ -324,8 +327,8 @@ def _update_imports(self, module: ast.Module) -> ast.Name | None:
324327
module.body.insert(
325328
len(non_empty_imports),
326329
ast.ImportFrom(
327-
module="typing",
328-
names=[ast.Name("TYPE_CHECKING")],
330+
module=TYPE_CHECKING_MODULE,
331+
names=[ast.Name(TYPE_CHECKING_FLAG)],
329332
),
330333
)
331334

0 commit comments

Comments
 (0)