Coverage for src/prisma/generator/_dsl_parser/transformer.py: 87%
24 statements
« prev ^ index » next coverage.py v7.2.7, created at 2024-08-27 18:25 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2024-08-27 18:25 +0000
1from __future__ import annotations
3from typing import Dict, cast
4from typing_extensions import TypedDict
6from ..._vendor.lark_schema_parser import Tree, Token, Transformer as LarkTransformer
9class TransformResult(TypedDict):
10 arguments: Arguments
13Arguments = Dict[str, str]
15ParseTree = Tree[Token]
18class DefinitionTransformer(LarkTransformer[Token, TransformResult]):
19 def start(self, items: tuple[ParseTree, Arguments | None]) -> TransformResult:
20 _, args = items
21 return {'arguments': args or {}}
23 def argument_list(self, items: list[tuple[str, str] | None] | None) -> Arguments:
24 if not items: 24 ↛ 25line 24 didn't jump to line 25, because the condition on line 24 was never true
25 return {}
27 return {
28 name: value
29 for name, value in [
30 # item can be None if there were no args passed
31 item
32 for item in items
33 if item is not None
34 ]
35 }
37 def argument(self, items: tuple[str, str]) -> tuple[str, str]:
38 return items
40 def key(self, items: tuple[Token]) -> str:
41 return cast(str, items[0].value)
43 def value(self, items: tuple[Token]) -> str:
44 value = cast(str, items[0].value)
46 if value.startswith(("'", '"')) and value.endswith(("'", '"')): 46 ↛ 48line 46 didn't jump to line 48, because the condition on line 46 was never false
47 return value[1:-1]
48 return value