Skip to content

Commit

Permalink
use unique_name_for_scope
Browse files Browse the repository at this point in the history
Signed-off-by: Janek Nouvertné <[email protected]>
  • Loading branch information
provinzkraut committed Sep 30, 2023
1 parent 1bbb2ef commit 7ca5bb7
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions litestar/dto/_codegen_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
TYPE_CHECKING,
Any,
Callable,
Container,
ContextManager,
Generator,
Mapping,
Expand All @@ -29,6 +28,7 @@
TransferType,
UnionType,
)
from litestar.utils.helpers import unique_name_for_scope

if TYPE_CHECKING:
from litestar.connection import ASGIConnection
Expand Down Expand Up @@ -192,15 +192,6 @@ def _create_transfer_data_fn(
)


def _gen_uniq_name(ctx: Container[str], name: str) -> str:
i = 0
while True:
unique_name = f"{name}_{i}"
if unique_name not in ctx:
return unique_name
i += 1


class FieldAccessManager(Protocol):
def __call__(self, source_name: str, field_name: str, expect_optional: bool) -> ContextManager[str]:
...
Expand All @@ -221,12 +212,12 @@ def __init__(self, is_data_field: bool, override_serialization_name: bool, neste
self._re_index_access = re.compile(r"\[['\"](\w+?)['\"]]")

def _add_to_fn_globals(self, name: str, value: Any) -> str:
unique_name = _gen_uniq_name(self._fn_locals, name)
unique_name = unique_name_for_scope(name, self._fn_locals)
self._fn_locals[unique_name] = value
return unique_name

def _create_local_name(self, name: str) -> str:
unique_name = _gen_uniq_name(self.names, name)
unique_name = unique_name_for_scope(name, self.names)
self.names.add(unique_name)
return unique_name

Expand Down

0 comments on commit 7ca5bb7

Please sign in to comment.