[Mlir-commits] [mlir] [mlir][python] Fix some mypy violations (NFC) (PR #110606)

Keith Smiley llvmlistbot at llvm.org
Tue Oct 1 16:39:05 PDT 2024


https://github.com/keith updated https://github.com/llvm/llvm-project/pull/110606

>From 341aef007a9287ffc4ae7f8a762bf901b08fe3a7 Mon Sep 17 00:00:00 2001
From: Keith Smiley <keithbsmiley at gmail.com>
Date: Tue, 1 Oct 2024 00:35:06 +0000
Subject: [PATCH 1/4] [mlir][python] Fix some mypy violations (NFC)

---
 mlir/python/mlir/dialects/_ods_common.py | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/mlir/python/mlir/dialects/_ods_common.py b/mlir/python/mlir/dialects/_ods_common.py
index d40d936cdc83d6..87adc1f90cad06 100644
--- a/mlir/python/mlir/dialects/_ods_common.py
+++ b/mlir/python/mlir/dialects/_ods_common.py
@@ -3,6 +3,7 @@
 #  SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
 from typing import (
+    Any as _Any,
     List as _List,
     Optional as _Optional,
     Sequence as _Sequence,
@@ -12,7 +13,7 @@
 )
 
 from .._mlir_libs import _mlir as _cext
-from ..ir import (
+from ..ir import ( # type: ignore
     ArrayAttr,
     Attribute,
     BoolAttr,
@@ -143,7 +144,7 @@ def get_op_result_or_op_results(
         else op
     )
 
-ResultValueTypeTuple = _cext.ir.Operation, _cext.ir.OpView, _cext.ir.Value
+ResultValueTypeTuple = _Tuple[_cext.ir.Operation, _cext.ir.OpView, _cext.ir.Value]
 ResultValueT = _Union[ResultValueTypeTuple]
 VariadicResultValueT = _Union[ResultValueT, _Sequence[ResultValueT]]
 
@@ -244,8 +245,8 @@ def _dispatch_mixed_values(
 
 
 def _get_value_or_attribute_value(
-    value_or_attr: _Union[any, Attribute, ArrayAttr]
-) -> any:
+    value_or_attr: _Union[_Any, Attribute, ArrayAttr]
+) -> _Any:
     if isinstance(value_or_attr, Attribute) and hasattr(value_or_attr, "value"):
         return value_or_attr.value
     if isinstance(value_or_attr, ArrayAttr):
@@ -254,8 +255,8 @@ def _get_value_or_attribute_value(
 
 
 def _get_value_list(
-    sequence_or_array_attr: _Union[_Sequence[any], ArrayAttr]
-) -> _Sequence[any]:
+    sequence_or_array_attr: _Union[_Sequence[_Any], ArrayAttr]
+) -> _Sequence[_Any]:
     return [_get_value_or_attribute_value(v) for v in sequence_or_array_attr]
 
 

>From c84c143a5e7622b241f1590e0eb3ff62af855ca3 Mon Sep 17 00:00:00 2001
From: Keith Smiley <keithbsmiley at gmail.com>
Date: Tue, 1 Oct 2024 00:42:11 +0000
Subject: [PATCH 2/4] lint

---
 mlir/python/mlir/dialects/_ods_common.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/python/mlir/dialects/_ods_common.py b/mlir/python/mlir/dialects/_ods_common.py
index 87adc1f90cad06..86cbd26d518724 100644
--- a/mlir/python/mlir/dialects/_ods_common.py
+++ b/mlir/python/mlir/dialects/_ods_common.py
@@ -13,7 +13,7 @@
 )
 
 from .._mlir_libs import _mlir as _cext
-from ..ir import ( # type: ignore
+from ..ir import (  # type: ignore
     ArrayAttr,
     Attribute,
     BoolAttr,

>From 2089120d63e37340c531d4312886f2e58464ab39 Mon Sep 17 00:00:00 2001
From: Keith Smiley <keithbsmiley at gmail.com>
Date: Tue, 1 Oct 2024 20:27:14 +0000
Subject: [PATCH 3/4] union not tuple

---
 mlir/python/mlir/dialects/_ods_common.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/python/mlir/dialects/_ods_common.py b/mlir/python/mlir/dialects/_ods_common.py
index 86cbd26d518724..31353dfa09514b 100644
--- a/mlir/python/mlir/dialects/_ods_common.py
+++ b/mlir/python/mlir/dialects/_ods_common.py
@@ -144,7 +144,7 @@ def get_op_result_or_op_results(
         else op
     )
 
-ResultValueTypeTuple = _Tuple[_cext.ir.Operation, _cext.ir.OpView, _cext.ir.Value]
+ResultValueTypeTuple = _Union[_cext.ir.Operation, _cext.ir.OpView, _cext.ir.Value]
 ResultValueT = _Union[ResultValueTypeTuple]
 VariadicResultValueT = _Union[ResultValueT, _Sequence[ResultValueT]]
 

>From 64550c87c381113045f382c74e03e8257817d1f1 Mon Sep 17 00:00:00 2001
From: Keith Smiley <keithbsmiley at gmail.com>
Date: Tue, 1 Oct 2024 16:38:49 -0700
Subject: [PATCH 4/4] remove union

---
 mlir/python/mlir/dialects/_ods_common.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/python/mlir/dialects/_ods_common.py b/mlir/python/mlir/dialects/_ods_common.py
index 31353dfa09514b..165787f523a96f 100644
--- a/mlir/python/mlir/dialects/_ods_common.py
+++ b/mlir/python/mlir/dialects/_ods_common.py
@@ -144,7 +144,7 @@ def get_op_result_or_op_results(
         else op
     )
 
-ResultValueTypeTuple = _Union[_cext.ir.Operation, _cext.ir.OpView, _cext.ir.Value]
+ResultValueTypeTuple = _cext.ir.Operation, _cext.ir.OpView, _cext.ir.Value
 ResultValueT = _Union[ResultValueTypeTuple]
 VariadicResultValueT = _Union[ResultValueT, _Sequence[ResultValueT]]
 



More information about the Mlir-commits mailing list