[Mlir-commits] [mlir] [MLIR][Python] Add more field specifiers to Python-defined operations (PR #188064)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Mar 26 09:14:08 PDT 2026
================
@@ -108,25 +111,70 @@ def _lower(self, type_) -> ir.Value:
@dataclass
class FieldSpecifier:
+ type_: Any = None
infer_type: bool = False
default_is_none: bool = False
+ default_factory: Optional[Callable[[], Any]] = None
+ kw_only: bool = False
- def __post_init__(self):
- if self.infer_type and self.default_is_none:
- raise ValueError(
- "a field cannot be marked with both infer_type and default_is_none"
- )
-
- def kw_only(self) -> bool:
- return self.default_is_none or self.infer_type
+ def param_kind(self):
+ if self.default_is_none or self.default_factory or self.infer_type:
+ return ParameterKind.KEYWORD_ONLY_WITH_DEFAULT
+ if self.kw_only:
+ return ParameterKind.KEYWORD_ONLY_WITHOUT_DEFAULT
+ return ParameterKind.POSITIONAL_OR_KEYWORD
-def result(*, infer_type: bool = False) -> Any:
+def result(
+ *,
+ infer_type: bool = False,
+ default_factory: Optional[Callable[[], Any]] = None,
+ kw_only: bool = False,
+) -> Any:
----------------
PragmaTwice wrote:
For the `default_factory`, the result type can be `Sequence` or `Optional`, which can be related to variadicity.
https://github.com/llvm/llvm-project/pull/188064
More information about the Mlir-commits
mailing list