Skip to content

Commit

Permalink
Use constants for TYPE_CHECKING
Browse files Browse the repository at this point in the history
  • Loading branch information
bombsimon committed Mar 13, 2024
1 parent 794743b commit 26d089b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions ariadne_codegen/contrib/no_global_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

from ariadne_codegen import Plugin

TYPE_CHECKING_MODULE: str = "typing"
TYPE_CHECKING_FLAG: str = "TYPE_CHECKING"


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

import_if_type_checking = ast.If(
test=ast.Name(id="TYPE_CHECKING"),
test=ast.Name(id=TYPE_CHECKING_FLAG),
body=list(type_checking_imports.values()),
orelse=[],
)
Expand All @@ -324,8 +327,8 @@ def _update_imports(self, module: ast.Module) -> ast.Name | None:
module.body.insert(
len(non_empty_imports),
ast.ImportFrom(
module="typing",
names=[ast.Name("TYPE_CHECKING")],
module=TYPE_CHECKING_MODULE,
names=[ast.Name(TYPE_CHECKING_FLAG)],
),
)

Expand Down

0 comments on commit 26d089b

Please sign in to comment.