Skip to content

Commit

Permalink
refactor: FunctionExpression -> Expression for annotation only
Browse files Browse the repository at this point in the history
Also renamed constant `EXPR_ANNOTATION` -> `INPUT_ANNOTATION`
  • Loading branch information
dangotbanned committed Sep 19, 2024
1 parent b3006bc commit 54f7db0
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions tools/schemapi/vega_expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,13 @@
TEXT: Literal["text"] = "text"
CHILDREN: Literal["children"] = "children"

RETURN_ANNOTATION = "FunctionExpression"
EXPR_ANNOTATION = "IntoExpression"
RETURN_WRAPPER = "FunctionExpression"
RETURN_ANNOTATION = "Expression"
# NOTE: No benefit to annotating with the actual wrapper
# - `Expression` is shorter, and has all the functionality/attributes

INPUT_ANNOTATION = "IntoExpression"

NONE: Literal[r"None"] = r"None"
STAR_ARGS: Literal["*args"] = "*args"
DECORATOR = r"@classmethod"
Expand Down Expand Up @@ -348,9 +353,9 @@ def star_args() -> LiteralString:
def to_str(self) -> str:
"""Return as an annotated parameter, with a default if needed."""
if self.required:
return f"{self.name}: {EXPR_ANNOTATION}"
return f"{self.name}: {INPUT_ANNOTATION}"
elif not self.variadic:
return f"{self.name}: {EXPR_ANNOTATION} = {NONE}"
return f"{self.name}: {INPUT_ANNOTATION} = {NONE}"
else:
return self.star_args()

Expand Down Expand Up @@ -393,7 +398,7 @@ def render_expr_method(node: VegaExprNode, /) -> WorkInProgress:
body_params = STAR_ARGS[1:]
else:
body_params = f"({', '.join(param.name for param in node.parameters)})"
body = f"return {RETURN_ANNOTATION}({node.name}, {body_params})"
body = f"return {RETURN_WRAPPER}({node.name}, {body_params})"
return DECORATOR, node.to_signature(), node.doc, body


Expand Down

0 comments on commit 54f7db0

Please sign in to comment.