Compare commits

...

3 Commits

Author SHA1 Message Date
16239db479 feat(gen): add tuple expr to generator 2026-06-29 22:44:39 +02:00
dc2134c87d tests: update with multi-parameter generics 2026-06-29 22:43:08 +02:00
89f3c945e4 fix: minor fixes 2026-06-29 22:41:47 +02:00
8 changed files with 92 additions and 72 deletions

View File

@@ -1233,7 +1233,7 @@ class PythonTyper(
node: ast.Expression = ast.parse(value, mode="eval") node: ast.Expression = ast.parse(value, mode="eval")
return parser._parse_type(node.body) return parser._parse_type(node.body)
case p.VariableExpr(name=name): case p.VariableExpr(name=name):
return p.BaseType(location=location, base=name, param=None) return p.BaseType(location=location, base=name, args=())
case _: case _:
raise NotImplementedError raise NotImplementedError

View File

@@ -196,6 +196,11 @@ class Generator(p.Stmt.Visitor[ast.stmt], p.Expr.Visitor[ast.expr]):
step=expr.step.accept(self) if expr.step is not None else None, step=expr.step.accept(self) if expr.step is not None else None,
) )
def visit_tuple_expr(self, expr: p.TupleExpr) -> ast.expr:
return ast.Tuple(
elts=[item.accept(self) for item in expr.items],
)
def visit_raw_expr(self, expr: p.RawExpr) -> ast.expr: def visit_raw_expr(self, expr: p.RawExpr) -> ast.expr:
return expr.expr return expr.expr

View File

@@ -24,7 +24,7 @@
"type": { "type": {
"_type": "BaseType", "_type": "BaseType",
"base": "Meter", "base": "Meter",
"param": null "args": []
}, },
"expr": { "expr": {
"_type": "LiteralExpr", "_type": "LiteralExpr",
@@ -62,7 +62,7 @@
"type": { "type": {
"_type": "BaseType", "_type": "BaseType",
"base": "Second", "base": "Second",
"param": null "args": []
}, },
"expr": { "expr": {
"_type": "LiteralExpr", "_type": "LiteralExpr",

View File

@@ -317,7 +317,7 @@
"pos": 0, "pos": 0,
"name": "object", "name": "object",
"type": {}, "type": {},
"required": true "required": false
} }
], ],
"args": [], "args": [],

View File

@@ -16,7 +16,7 @@
"type": { "type": {
"_type": "BaseType", "_type": "BaseType",
"base": "bool", "base": "bool",
"param": null "args": []
} }
}, },
{ {
@@ -25,7 +25,7 @@
"type": { "type": {
"_type": "BaseType", "_type": "BaseType",
"base": "int", "base": "int",
"param": null "args": []
} }
}, },
{ {
@@ -36,7 +36,7 @@
"type": { "type": {
"_type": "BaseType", "_type": "BaseType",
"base": "float", "base": "float",
"param": null "args": []
}, },
"constraint": "(_ > 0) + (_ < 250)" "constraint": "(_ > 0) + (_ < 250)"
} }
@@ -47,7 +47,7 @@
"type": { "type": {
"_type": "BaseType", "_type": "BaseType",
"base": "str", "base": "str",
"param": null "args": []
} }
}, },
{ {
@@ -56,7 +56,7 @@
"type": { "type": {
"_type": "BaseType", "_type": "BaseType",
"base": "datetime", "base": "datetime",
"param": null "args": []
} }
}, },
{ {
@@ -65,7 +65,7 @@
"type": { "type": {
"_type": "BaseType", "_type": "BaseType",
"base": "float", "base": "float",
"param": null "args": []
} }
}, },
{ {
@@ -79,7 +79,7 @@
"type": { "type": {
"_type": "BaseType", "_type": "BaseType",
"base": "_", "base": "_",
"param": null "args": []
} }
} }
] ]

View File

@@ -16,7 +16,7 @@
"type": { "type": {
"_type": "BaseType", "_type": "BaseType",
"base": "GeoLocation", "base": "GeoLocation",
"param": null "args": []
} }
} }
] ]
@@ -28,11 +28,13 @@
"type": { "type": {
"_type": "BaseType", "_type": "BaseType",
"base": "Column", "base": "Column",
"param": { "args": [
"_type": "BaseType", {
"base": "GeoLocation", "_type": "BaseType",
"param": null "base": "GeoLocation",
} "args": []
}
]
} }
}, },
{ {
@@ -65,11 +67,13 @@
"type": { "type": {
"_type": "BaseType", "_type": "BaseType",
"base": "Column", "base": "Column",
"param": { "args": [
"_type": "BaseType", {
"base": "GeoLocation", "_type": "BaseType",
"param": null "base": "GeoLocation",
} "args": []
}
]
} }
}, },
{ {
@@ -117,7 +121,7 @@
"type": { "type": {
"_type": "BaseType", "_type": "BaseType",
"base": "Latitude", "base": "Latitude",
"param": null "args": []
} }
}, },
{ {
@@ -146,7 +150,7 @@
"type": { "type": {
"_type": "BaseType", "_type": "BaseType",
"base": "Latitude", "base": "Latitude",
"param": null "args": []
} }
}, },
{ {
@@ -175,11 +179,13 @@
"type": { "type": {
"_type": "BaseType", "_type": "BaseType",
"base": "Difference", "base": "Difference",
"param": { "args": [
"_type": "BaseType", {
"base": "Latitude", "_type": "BaseType",
"param": null "base": "Latitude",
} "args": []
}
]
} }
}, },
{ {
@@ -217,7 +223,7 @@
"type": { "type": {
"_type": "BaseType", "_type": "BaseType",
"base": "int", "base": "int",
"param": null "args": []
}, },
"constraint": "_ >= 0" "constraint": "_ >= 0"
} }
@@ -230,7 +236,7 @@
"type": { "type": {
"_type": "BaseType", "_type": "BaseType",
"base": "float", "base": "float",
"param": null "args": []
}, },
"constraint": "_ >= 0" "constraint": "_ >= 0"
} }
@@ -252,7 +258,7 @@
"type": { "type": {
"_type": "BaseType", "_type": "BaseType",
"base": "int", "base": "int",
"param": null "args": []
}, },
"constraint": "Positive" "constraint": "Positive"
} }
@@ -265,7 +271,7 @@
"type": { "type": {
"_type": "BaseType", "_type": "BaseType",
"base": "float", "base": "float",
"param": null "args": []
}, },
"constraint": "Positive" "constraint": "Positive"
} }

View File

@@ -14,15 +14,17 @@
"type": { "type": {
"_type": "BaseType", "_type": "BaseType",
"base": "Column", "base": "Column",
"param": { "args": [
"_type": "ConstraintType", {
"type": { "_type": "ConstraintType",
"_type": "BaseType", "type": {
"base": "float", "_type": "BaseType",
"param": null "base": "float",
}, "args": []
"constraint": "0 <= _ <= 1" },
} "constraint": "0 <= _ <= 1"
}
]
}, },
"default": null "default": null
}, },
@@ -31,15 +33,17 @@
"type": { "type": {
"_type": "BaseType", "_type": "BaseType",
"base": "Column", "base": "Column",
"param": { "args": [
"_type": "ConstraintType", {
"type": { "_type": "ConstraintType",
"_type": "BaseType", "type": {
"base": "float", "_type": "BaseType",
"param": null "base": "float",
}, "args": []
"constraint": "0 <= _ <= 1" },
} "constraint": "0 <= _ <= 1"
}
]
}, },
"default": null "default": null
} }
@@ -50,15 +54,17 @@
"returns": { "returns": {
"_type": "BaseType", "_type": "BaseType",
"base": "Column", "base": "Column",
"param": { "args": [
"_type": "ConstraintType", {
"type": { "_type": "ConstraintType",
"_type": "BaseType", "type": {
"base": "float", "_type": "BaseType",
"param": null "base": "float",
}, "args": []
"constraint": "0 <= _ <= 2" },
} "constraint": "0 <= _ <= 2"
}
]
}, },
"body": [ "body": [
{ {
@@ -67,15 +73,17 @@
"type": { "type": {
"_type": "BaseType", "_type": "BaseType",
"base": "Column", "base": "Column",
"param": { "args": [
"_type": "ConstraintType", {
"type": { "_type": "ConstraintType",
"_type": "BaseType", "type": {
"base": "float", "_type": "BaseType",
"param": null "base": "float",
}, "args": []
"constraint": "0 <= _ <= 2" },
} "constraint": "0 <= _ <= 2"
}
]
} }
}, },
{ {
@@ -117,7 +125,7 @@
"type": { "type": {
"_type": "BaseType", "_type": "BaseType",
"base": "int", "base": "int",
"param": null "args": []
}, },
"default": null "default": null
} }
@@ -128,7 +136,7 @@
"type": { "type": {
"_type": "BaseType", "_type": "BaseType",
"base": "float", "base": "float",
"param": null "args": []
}, },
"default": null "default": null
} }
@@ -140,7 +148,7 @@
"type": { "type": {
"_type": "BaseType", "_type": "BaseType",
"base": "str", "base": "str",
"param": null "args": []
}, },
"default": null "default": null
} }

View File

@@ -30,6 +30,7 @@ from midas.ast.python import (
Stmt, Stmt,
SubscriptExpr, SubscriptExpr,
TernaryExpr, TernaryExpr,
TupleExpr,
TypeAssign, TypeAssign,
UnaryExpr, UnaryExpr,
VariableExpr, VariableExpr,