[Mlir-commits] [mlir] A few tweaks to the MLIR .pyi files (PR #110488)

Sergei Lebedev llvmlistbot at llvm.org
Mon Sep 30 03:47:52 PDT 2024


https://github.com/superbobry created https://github.com/llvm/llvm-project/pull/110488

None

>From 50ff0e50b4ccbf312d83c25bdcedade12a294748 Mon Sep 17 00:00:00 2001
From: Sergei Lebedev <slebedev at google.com>
Date: Mon, 30 Sep 2024 10:32:50 +0000
Subject: [PATCH 1/3] Adding the missing `MemRefType.get_strides_and_offset`

---
 mlir/python/mlir/_mlir_libs/_mlir/ir.pyi | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/mlir/python/mlir/_mlir_libs/_mlir/ir.pyi b/mlir/python/mlir/_mlir_libs/_mlir/ir.pyi
index 4d5b4cef9d8aa8..6dc084ce454931 100644
--- a/mlir/python/mlir/_mlir_libs/_mlir/ir.pyi
+++ b/mlir/python/mlir/_mlir_libs/_mlir/ir.pyi
@@ -2110,6 +2110,10 @@ class MemRefType(ShapedType):
         """
     @property
     def typeid(self) -> TypeID: ...
+    def get_strides_and_offset(self) -> tuple[list[int], list[int]]:
+        """
+        The strides and offset of the MemRef type.
+        """
 
 class Module:
     @staticmethod

>From 72fa82f19631688246380deeb015b0ef455e1db8 Mon Sep 17 00:00:00 2001
From: Sergei Lebedev <slebedev at google.com>
Date: Mon, 30 Sep 2024 10:35:48 +0000
Subject: [PATCH 2/3] Ran pyupgrade on the .pyi files

The exact commands to repro

    python3 -m pyupgrade --py310-plus --keep-percent-format mlir/python/mlir/_mlir_libs/**/*.pyi
    python3 -m ruff check --select=F401 --fix mlir/python/mlir/_mlir_libs/**/*.pyi
---
 .../python/mlir/_mlir_libs/_mlir/__init__.pyi |   3 +-
 .../mlir/_mlir_libs/_mlir/dialects/pdl.pyi    |   9 +-
 .../mlir/_mlir_libs/_mlir/dialects/quant.pyi  |   7 +-
 .../_mlir/dialects/transform/__init__.pyi     |   5 +-
 mlir/python/mlir/_mlir_libs/_mlir/ir.pyi      | 360 +++++++++---------
 .../mlir/_mlir_libs/_mlir/passmanager.pyi     |   5 +-
 .../mlir/_mlir_libs/_mlirExecutionEngine.pyi  |   2 +-
 7 files changed, 190 insertions(+), 201 deletions(-)

diff --git a/mlir/python/mlir/_mlir_libs/_mlir/__init__.pyi b/mlir/python/mlir/_mlir_libs/_mlir/__init__.pyi
index 93b978c75540f4..42694747e5f24f 100644
--- a/mlir/python/mlir/_mlir_libs/_mlir/__init__.pyi
+++ b/mlir/python/mlir/_mlir_libs/_mlir/__init__.pyi
@@ -1,9 +1,8 @@
-from typing import List
 
 globals: "_Globals"
 
 class _Globals:
-    dialect_search_modules: List[str]
+    dialect_search_modules: list[str]
     def _register_dialect_impl(self, dialect_namespace: str, dialect_class: type) -> None: ...
     def _register_operation_impl(self, operation_name: str, operation_class: type) -> None: ...
     def append_dialect_search_prefix(self, module_name: str) -> None: ...
diff --git a/mlir/python/mlir/_mlir_libs/_mlir/dialects/pdl.pyi b/mlir/python/mlir/_mlir_libs/_mlir/dialects/pdl.pyi
index 8ec944d191c6ff..d12c6839deabaf 100644
--- a/mlir/python/mlir/_mlir_libs/_mlir/dialects/pdl.pyi
+++ b/mlir/python/mlir/_mlir_libs/_mlir/dialects/pdl.pyi
@@ -2,7 +2,6 @@
 #  See https://llvm.org/LICENSE.txt for license information.
 #  SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
-from typing import Optional
 
 from mlir.ir import Type, Context
 
@@ -26,7 +25,7 @@ class AttributeType(Type):
   def isinstance(type: Type) -> bool: ...
 
   @staticmethod
-  def get(context: Optional[Context] = None) -> AttributeType: ...
+  def get(context: Context | None = None) -> AttributeType: ...
 
 
 class OperationType(Type):
@@ -34,7 +33,7 @@ class OperationType(Type):
   def isinstance(type: Type) -> bool: ...
 
   @staticmethod
-  def get(context: Optional[Context] = None) -> OperationType: ...
+  def get(context: Context | None = None) -> OperationType: ...
 
 
 class RangeType(Type):
@@ -53,7 +52,7 @@ class TypeType(Type):
   def isinstance(type: Type) -> bool: ...
 
   @staticmethod
-  def get(context: Optional[Context] = None) -> TypeType: ...
+  def get(context: Context | None = None) -> TypeType: ...
 
 
 class ValueType(Type):
@@ -61,4 +60,4 @@ class ValueType(Type):
   def isinstance(type: Type) -> bool: ...
 
   @staticmethod
-  def get(context: Optional[Context] = None) -> ValueType: ...
+  def get(context: Context | None = None) -> ValueType: ...
diff --git a/mlir/python/mlir/_mlir_libs/_mlir/dialects/quant.pyi b/mlir/python/mlir/_mlir_libs/_mlir/dialects/quant.pyi
index c9c66d52b8c250..a10bc693ba6001 100644
--- a/mlir/python/mlir/_mlir_libs/_mlir/dialects/quant.pyi
+++ b/mlir/python/mlir/_mlir_libs/_mlir/dialects/quant.pyi
@@ -2,7 +2,6 @@
 #  See https://llvm.org/LICENSE.txt for license information.
 #  SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
-from typing import List
 
 from mlir.ir import Type
 
@@ -94,15 +93,15 @@ class UniformQuantizedPerAxisType(QuantizedType):
 
   @classmethod
   def get(cls, flags: int, storage_type: Type, expressed_type: Type,
-          scales: List[float], zero_points: List[int], quantized_dimension: int,
+          scales: list[float], zero_points: list[int], quantized_dimension: int,
           storage_type_min: int, storage_type_max: int):
     ...
 
   @property
-  def scales(self) -> List[float]: ...
+  def scales(self) -> list[float]: ...
 
   @property
-  def zero_points(self) -> List[float]: ...
+  def zero_points(self) -> list[float]: ...
 
   @property
   def quantized_dimension(self) -> int: ...
diff --git a/mlir/python/mlir/_mlir_libs/_mlir/dialects/transform/__init__.pyi b/mlir/python/mlir/_mlir_libs/_mlir/dialects/transform/__init__.pyi
index 2a29541734a821..a3f1b09102379f 100644
--- a/mlir/python/mlir/_mlir_libs/_mlir/dialects/transform/__init__.pyi
+++ b/mlir/python/mlir/_mlir_libs/_mlir/dialects/transform/__init__.pyi
@@ -2,7 +2,6 @@
 #  See https://llvm.org/LICENSE.txt for license information.
 #  SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
-from typing import Optional
 
 from mlir.ir import Type, Context
 
@@ -12,7 +11,7 @@ class AnyOpType(Type):
   def isinstance(type: Type) -> bool: ...
 
   @staticmethod
-  def get(context: Optional[Context] = None) -> AnyOpType: ...
+  def get(context: Context | None = None) -> AnyOpType: ...
 
 
 class OperationType(Type):
@@ -20,7 +19,7 @@ class OperationType(Type):
   def isinstance(type: Type) -> bool: ...
 
   @staticmethod
-  def get(operation_name: str, context: Optional[Context] = None) -> OperationType: ...
+  def get(operation_name: str, context: Context | None = None) -> OperationType: ...
 
   @property
   def operation_name(self) -> str: ...
diff --git a/mlir/python/mlir/_mlir_libs/_mlir/ir.pyi b/mlir/python/mlir/_mlir_libs/_mlir/ir.pyi
index 6dc084ce454931..aadbb781c2c414 100644
--- a/mlir/python/mlir/_mlir_libs/_mlir/ir.pyi
+++ b/mlir/python/mlir/_mlir_libs/_mlir/ir.pyi
@@ -47,17 +47,11 @@ import collections
 import io
 from typing import (
     Any,
-    Callable,
     ClassVar,
-    Dict,
-    List,
-    Optional,
-    Sequence,
-    Tuple,
     Type as _Type,
     TypeVar,
-    Union,
 )
+from collections.abc import Callable, Sequence
 
 from typing import overload
 
@@ -210,14 +204,14 @@ class _OperationBase:
     def get_asm(
         self,
         binary: bool = False,
-        large_elements_limit: Optional[int] = None,
+        large_elements_limit: int | None = None,
         enable_debug_info: bool = False,
         pretty_debug_info: bool = False,
         print_generic_op_form: bool = False,
         use_local_scope: bool = False,
         assume_verified: bool = False,
         skip_regions: bool = False,
-    ) -> Union[io.BytesIO, io.StringIO]:
+    ) -> io.BytesIO | io.StringIO:
         """
         Gets the assembly form of the operation with all options available.
 
@@ -242,7 +236,7 @@ class _OperationBase:
     def print(
         self,
         state: AsmState,
-        file: Optional[Any] = None,
+        file: Any | None = None,
         binary: bool = False,
     ) -> None:
         """
@@ -256,13 +250,13 @@ class _OperationBase:
     @overload
     def print(
         self,
-        large_elements_limit: Optional[int] = None,
+        large_elements_limit: int | None = None,
         enable_debug_info: bool = False,
         pretty_debug_info: bool = False,
         print_generic_op_form: bool = False,
         use_local_scope: bool = False,
         assume_verified: bool = False,
-        file: Optional[Any] = None,
+        file: Any | None = None,
         binary: bool = False,
         skip_regions: bool = False,
     ) -> None:
@@ -296,7 +290,7 @@ class _OperationBase:
         """
         Verify the operation. Raises MLIRError if verification fails, and returns true otherwise.
         """
-    def write_bytecode(self, file: Any, desired_version: Optional[int] = None) -> None:
+    def write_bytecode(self, file: Any, desired_version: int | None = None) -> None:
         """
         Write the bytecode form of the operation to a file like object.
 
@@ -325,7 +319,7 @@ class _OperationBase:
     @property
     def operands(self) -> OpOperandList: ...
     @property
-    def parent(self) -> Optional[_OperationBase]: ...
+    def parent(self) -> _OperationBase | None: ...
     @property
     def regions(self) -> RegionSequence: ...
     @property
@@ -380,13 +374,13 @@ class AffineExpr:
         """
     @staticmethod
     def get_constant(
-        value: int, context: Optional[Context] = None
+        value: int, context: Context | None = None
     ) -> AffineConstantExpr:
         """
         Gets a constant affine expression with the given value.
         """
     @staticmethod
-    def get_dim(position: int, context: Optional[Context] = None) -> AffineDimExpr:
+    def get_dim(position: int, context: Context | None = None) -> AffineDimExpr:
         """
         Gets an affine expression of a dimension at the given position.
         """
@@ -446,7 +440,7 @@ class AffineExpr:
         """
     @staticmethod
     def get_symbol(
-        position: int, context: Optional[Context] = None
+        position: int, context: Context | None = None
     ) -> AffineSymbolExpr:
         """
         Gets an affine expression of a symbol at the given position.
@@ -489,7 +483,7 @@ class AffineExpr:
 
 class Attribute:
     @staticmethod
-    def parse(asm: str | bytes, context: Optional[Context] = None) -> Attribute:
+    def parse(asm: str | bytes, context: Context | None = None) -> Attribute:
         """
         Parses an attribute from an assembly form. Raises an MLIRError on failure.
         """
@@ -530,7 +524,7 @@ class Attribute:
 
 class Type:
     @staticmethod
-    def parse(asm: str | bytes, context: Optional[Context] = None) -> Type:
+    def parse(asm: str | bytes, context: Context | None = None) -> Type:
         """
         Parses the assembly form of a type.
 
@@ -640,7 +634,7 @@ class AffineCeilDivExpr(AffineBinaryExpr):
 
 class AffineConstantExpr(AffineExpr):
     @staticmethod
-    def get(value: int, context: Optional[Context] = None) -> AffineConstantExpr: ...
+    def get(value: int, context: Context | None = None) -> AffineConstantExpr: ...
     @staticmethod
     def isinstance(other: AffineExpr) -> bool: ...
     def __init__(self, expr: AffineExpr) -> None: ...
@@ -649,7 +643,7 @@ class AffineConstantExpr(AffineExpr):
 
 class AffineDimExpr(AffineExpr):
     @staticmethod
-    def get(position: int, context: Optional[Context] = None) -> AffineDimExpr: ...
+    def get(position: int, context: Context | None = None) -> AffineDimExpr: ...
     @staticmethod
     def isinstance(other: AffineExpr) -> bool: ...
     def __init__(self, expr: AffineExpr) -> None: ...
@@ -657,7 +651,7 @@ class AffineDimExpr(AffineExpr):
     def position(self) -> int: ...
 
 class AffineExprList:
-    def __add__(self, arg0: AffineExprList) -> List[AffineExpr]: ...
+    def __add__(self, arg0: AffineExprList) -> list[AffineExpr]: ...
 
 class AffineFloorDivExpr(AffineBinaryExpr):
     @staticmethod
@@ -669,43 +663,43 @@ class AffineFloorDivExpr(AffineBinaryExpr):
 class AffineMap:
     @staticmethod
     def compress_unused_symbols(
-        arg0: List, arg1: Optional[Context]
-    ) -> List[AffineMap]: ...
+        arg0: list, arg1: Context | None
+    ) -> list[AffineMap]: ...
     @staticmethod
     def get(
         dim_count: int,
         symbol_count: int,
-        exprs: List,
-        context: Optional[Context] = None,
+        exprs: list,
+        context: Context | None = None,
     ) -> AffineMap:
         """
         Gets a map with the given expressions as results.
         """
     @staticmethod
-    def get_constant(value: int, context: Optional[Context] = None) -> AffineMap:
+    def get_constant(value: int, context: Context | None = None) -> AffineMap:
         """
         Gets an affine map with a single constant result
         """
     @staticmethod
-    def get_empty(context: Optional[Context] = None) -> AffineMap:
+    def get_empty(context: Context | None = None) -> AffineMap:
         """
         Gets an empty affine map.
         """
     @staticmethod
-    def get_identity(n_dims: int, context: Optional[Context] = None) -> AffineMap:
+    def get_identity(n_dims: int, context: Context | None = None) -> AffineMap:
         """
         Gets an identity map with the given number of dimensions.
         """
     @staticmethod
     def get_minor_identity(
-        n_dims: int, n_results: int, context: Optional[Context] = None
+        n_dims: int, n_results: int, context: Context | None = None
     ) -> AffineMap:
         """
         Gets a minor identity map with the given number of dimensions and results.
         """
     @staticmethod
     def get_permutation(
-        permutation: List[int], context: Optional[Context] = None
+        permutation: list[int], context: Context | None = None
     ) -> AffineMap:
         """
         Gets an affine map that permutes its inputs.
@@ -722,7 +716,7 @@ class AffineMap:
         """
     def get_major_submap(self, n_results: int) -> AffineMap: ...
     def get_minor_submap(self, n_results: int) -> AffineMap: ...
-    def get_submap(self, result_positions: List[int]) -> AffineMap: ...
+    def get_submap(self, result_positions: list[int]) -> AffineMap: ...
     def replace(
         self,
         expr: AffineExpr,
@@ -748,7 +742,7 @@ class AffineMap:
     @property
     def n_symbols(self) -> int: ...
     @property
-    def results(self) -> "AffineMapExprList": ...
+    def results(self) -> AffineMapExprList: ...
 
 class AffineMapAttr(Attribute):
     static_typeid: ClassVar[TypeID]
@@ -781,7 +775,7 @@ class AffineMulExpr(AffineBinaryExpr):
 
 class AffineSymbolExpr(AffineExpr):
     @staticmethod
-    def get(position: int, context: Optional[Context] = None) -> AffineSymbolExpr: ...
+    def get(position: int, context: Context | None = None) -> AffineSymbolExpr: ...
     @staticmethod
     def isinstance(other: AffineExpr) -> bool: ...
     def __init__(self, expr: AffineExpr) -> None: ...
@@ -791,13 +785,13 @@ class AffineSymbolExpr(AffineExpr):
 class ArrayAttr(Attribute):
     static_typeid: ClassVar[TypeID]
     @staticmethod
-    def get(attributes: List, context: Optional[Context] = None) -> ArrayAttr:
+    def get(attributes: list, context: Context | None = None) -> ArrayAttr:
         """
         Gets a uniqued Array attribute
         """
     @staticmethod
     def isinstance(other: Attribute) -> bool: ...
-    def __add__(self, arg0: List) -> ArrayAttr: ...
+    def __add__(self, arg0: list) -> ArrayAttr: ...
     def __getitem__(self, arg0: int) -> Attribute: ...
     def __init__(self, cast_from_attr: Attribute) -> None: ...
     def __iter__(
@@ -835,7 +829,7 @@ class AttrBuilder:
 class BF16Type(Type):
     static_typeid: ClassVar[TypeID]
     @staticmethod
-    def get(context: Optional[Context] = None) -> BF16Type:
+    def get(context: Context | None = None) -> BF16Type:
         """
         Create a bf16 type.
         """
@@ -849,8 +843,8 @@ class Block:
     @staticmethod
     def create_at_start(
         parent: Region,
-        arg_types: List[Type],
-        arg_locs: Optional[Sequence] = None,
+        arg_types: list[Type],
+        arg_locs: Sequence | None = None,
     ) -> Block:
         """
         Creates and returns a new Block at the beginning of the given region (with given argument types and locations).
@@ -876,11 +870,11 @@ class Block:
         """
         Append this block to a region, transferring ownership if necessary
         """
-    def create_after(self, *args, arg_locs: Optional[Sequence] = None) -> Block:
+    def create_after(self, *args, arg_locs: Sequence | None = None) -> Block:
         """
         Creates and returns a new Block after this block (with given argument types and locations).
         """
-    def create_before(self, *args, arg_locs: Optional[Sequence] = None) -> Block:
+    def create_before(self, *args, arg_locs: Sequence | None = None) -> Block:
         """
         Creates and returns a new Block before this block (with given argument types and locations).
         """
@@ -924,9 +918,9 @@ class BlockArgumentList:
     @overload
     def __getitem__(self, arg0: slice) -> BlockArgumentList: ...
     def __len__(self) -> int: ...
-    def __add__(self, arg0: BlockArgumentList) -> List[BlockArgument]: ...
+    def __add__(self, arg0: BlockArgumentList) -> list[BlockArgument]: ...
     @property
-    def types(self) -> List[Type]: ...
+    def types(self) -> list[Type]: ...
 
 class BlockIterator:
     def __iter__(self) -> BlockIterator: ...
@@ -936,7 +930,7 @@ class BlockList:
     def __getitem__(self, arg0: int) -> Block: ...
     def __iter__(self) -> BlockIterator: ...
     def __len__(self) -> int: ...
-    def append(self, *args, arg_locs: Optional[Sequence] = None) -> Block:
+    def append(self, *args, arg_locs: Sequence | None = None) -> Block:
         """
         Appends a new block, with argument types as positional args.
 
@@ -946,7 +940,7 @@ class BlockList:
 
 class BoolAttr(Attribute):
     @staticmethod
-    def get(value: bool, context: Optional[Context] = None) -> BoolAttr:
+    def get(value: bool, context: Context | None = None) -> BoolAttr:
         """
         Gets an uniqued bool attribute
         """
@@ -1000,7 +994,7 @@ class Context:
     def _get_context_again(self) -> Context: ...
     def _get_live_module_count(self) -> int: ...
     def _get_live_operation_count(self) -> int: ...
-    def _get_live_operation_objects(self) -> List[Operation]: ...
+    def _get_live_operation_objects(self) -> list[Operation]: ...
     def append_dialect_registry(self, registry: DialectRegistry) -> None: ...
     def attach_diagnostic_handler(
         self, callback: Callable[[Diagnostic], bool]
@@ -1031,14 +1025,14 @@ class Context:
 class DenseBoolArrayAttr(Attribute):
     @staticmethod
     def get(
-        values: Sequence[bool], context: Optional[Context] = None
+        values: Sequence[bool], context: Context | None = None
     ) -> DenseBoolArrayAttr:
         """
         Gets a uniqued dense array attribute
         """
     @staticmethod
     def isinstance(other: Attribute) -> bool: ...
-    def __add__(self, arg0: List) -> DenseBoolArrayAttr: ...
+    def __add__(self, arg0: list) -> DenseBoolArrayAttr: ...
     def __getitem__(self, arg0: int) -> bool: ...
     def __init__(self, cast_from_attr: Attribute) -> None: ...
     def __iter__(
@@ -1061,9 +1055,9 @@ class DenseElementsAttr(Attribute):
     def get(
         array: Buffer,
         signless: bool = True,
-        type: Optional[Type] = None,
-        shape: Optional[List[int]] = None,
-        context: Optional[Context] = None,
+        type: Type | None = None,
+        shape: list[int] | None = None,
+        context: Context | None = None,
     ) -> DenseElementsAttr:
         """
         Gets a DenseElementsAttr from a Python buffer or array.
@@ -1128,14 +1122,14 @@ class DenseElementsAttr(Attribute):
 class DenseF32ArrayAttr(Attribute):
     @staticmethod
     def get(
-        values: Sequence[float], context: Optional[Context] = None
+        values: Sequence[float], context: Context | None = None
     ) -> DenseF32ArrayAttr:
         """
         Gets a uniqued dense array attribute
         """
     @staticmethod
     def isinstance(other: Attribute) -> bool: ...
-    def __add__(self, arg0: List) -> DenseF32ArrayAttr: ...
+    def __add__(self, arg0: list) -> DenseF32ArrayAttr: ...
     def __getitem__(self, arg0: int) -> float: ...
     def __init__(self, cast_from_attr: Attribute) -> None: ...
     def __iter__(
@@ -1156,14 +1150,14 @@ class DenseF32ArrayIterator:
 class DenseF64ArrayAttr(Attribute):
     @staticmethod
     def get(
-        values: Sequence[float], context: Optional[Context] = None
+        values: Sequence[float], context: Context | None = None
     ) -> DenseF64ArrayAttr:
         """
         Gets a uniqued dense array attribute
         """
     @staticmethod
     def isinstance(other: Attribute) -> bool: ...
-    def __add__(self, arg0: List) -> DenseF64ArrayAttr: ...
+    def __add__(self, arg0: list) -> DenseF64ArrayAttr: ...
     def __getitem__(self, arg0: int) -> float: ...
     def __init__(self, cast_from_attr: Attribute) -> None: ...
     def __iter__(
@@ -1186,9 +1180,9 @@ class DenseFPElementsAttr(DenseElementsAttr):
     def get(
         array: Buffer,
         signless: bool = True,
-        type: Optional[Type] = None,
-        shape: Optional[List[int]] = None,
-        context: Optional[Context] = None,
+        type: Type | None = None,
+        shape: list[int] | None = None,
+        context: Context | None = None,
     ) -> DenseFPElementsAttr: ...
     @staticmethod
     def isinstance(other: Attribute) -> bool: ...
@@ -1203,13 +1197,13 @@ class DenseFPElementsAttr(DenseElementsAttr):
 
 class DenseI16ArrayAttr(Attribute):
     @staticmethod
-    def get(values: Sequence[int], context: Optional[Context] = None) -> DenseI16ArrayAttr:
+    def get(values: Sequence[int], context: Context | None = None) -> DenseI16ArrayAttr:
         """
         Gets a uniqued dense array attribute
         """
     @staticmethod
     def isinstance(other: Attribute) -> bool: ...
-    def __add__(self, arg0: List) -> DenseI16ArrayAttr: ...
+    def __add__(self, arg0: list) -> DenseI16ArrayAttr: ...
     def __getitem__(self, arg0: int) -> int: ...
     def __init__(self, cast_from_attr: Attribute) -> None: ...
     def __iter__(
@@ -1229,13 +1223,13 @@ class DenseI16ArrayIterator:
 
 class DenseI32ArrayAttr(Attribute):
     @staticmethod
-    def get(values: Sequence[int], context: Optional[Context] = None) -> DenseI32ArrayAttr:
+    def get(values: Sequence[int], context: Context | None = None) -> DenseI32ArrayAttr:
         """
         Gets a uniqued dense array attribute
         """
     @staticmethod
     def isinstance(other: Attribute) -> bool: ...
-    def __add__(self, arg0: List) -> DenseI32ArrayAttr: ...
+    def __add__(self, arg0: list) -> DenseI32ArrayAttr: ...
     def __getitem__(self, arg0: int) -> int: ...
     def __init__(self, cast_from_attr: Attribute) -> None: ...
     def __iter__(
@@ -1255,13 +1249,13 @@ class DenseI32ArrayIterator:
 
 class DenseI64ArrayAttr(Attribute):
     @staticmethod
-    def get(values: Sequence[int], context: Optional[Context] = None) -> DenseI64ArrayAttr:
+    def get(values: Sequence[int], context: Context | None = None) -> DenseI64ArrayAttr:
         """
         Gets a uniqued dense array attribute
         """
     @staticmethod
     def isinstance(other: Attribute) -> bool: ...
-    def __add__(self, arg0: List) -> DenseI64ArrayAttr: ...
+    def __add__(self, arg0: list) -> DenseI64ArrayAttr: ...
     def __getitem__(self, arg0: int) -> int: ...
     def __init__(self, cast_from_attr: Attribute) -> None: ...
     def __iter__(
@@ -1281,13 +1275,13 @@ class DenseI64ArrayIterator:
 
 class DenseI8ArrayAttr(Attribute):
     @staticmethod
-    def get(values: Sequence[int], context: Optional[Context] = None) -> DenseI8ArrayAttr:
+    def get(values: Sequence[int], context: Context | None = None) -> DenseI8ArrayAttr:
         """
         Gets a uniqued dense array attribute
         """
     @staticmethod
     def isinstance(other: Attribute) -> bool: ...
-    def __add__(self, arg0: List) -> DenseI8ArrayAttr: ...
+    def __add__(self, arg0: list) -> DenseI8ArrayAttr: ...
     def __getitem__(self, arg0: int) -> int: ...
     def __init__(self, cast_from_attr: Attribute) -> None: ...
     def __iter__(
@@ -1310,9 +1304,9 @@ class DenseIntElementsAttr(DenseElementsAttr):
     def get(
         array: Buffer,
         signless: bool = True,
-        type: Optional[Type] = None,
-        shape: Optional[List[int]] = None,
-        context: Optional[Context] = None,
+        type: Type | None = None,
+        shape: list[int] | None = None,
+        context: Context | None = None,
     ) -> DenseIntElementsAttr: ...
     @staticmethod
     def isinstance(other: Attribute) -> bool: ...
@@ -1331,9 +1325,9 @@ class DenseResourceElementsAttr(Attribute):
         array: Buffer,
         name: str,
         type: Type,
-        alignment: Optional[int] = None,
+        alignment: int | None = None,
         is_mutable: bool = False,
-        context: Optional[Context] = None,
+        context: Context | None = None,
     ) -> DenseResourceElementsAttr:
         """
         Gets a DenseResourceElementsAttr from a Python buffer or array.
@@ -1376,7 +1370,7 @@ class Diagnostic:
     @property
     def message(self) -> str: ...
     @property
-    def notes(self) -> Tuple[Diagnostic]: ...
+    def notes(self) -> tuple[Diagnostic]: ...
     @property
     def severity(self) -> DiagnosticSeverity: ...
 
@@ -1396,7 +1390,7 @@ class DiagnosticInfo:
     @property
     def message(self) -> str: ...
     @property
-    def notes(self) -> List[DiagnosticInfo]: ...
+    def notes(self) -> list[DiagnosticInfo]: ...
     @property
     def severity(self) -> DiagnosticSeverity: ...
 
@@ -1418,7 +1412,7 @@ class DiagnosticSeverity:
     REMARK: ClassVar[DiagnosticSeverity]  # value = <DiagnosticSeverity.REMARK: 3>
     WARNING: ClassVar[DiagnosticSeverity]  # value = <DiagnosticSeverity.WARNING: 1>
     __members__: ClassVar[
-        Dict[str, DiagnosticSeverity]
+        dict[str, DiagnosticSeverity]
     ]  # value = {'ERROR': <DiagnosticSeverity.ERROR: 0>, 'WARNING': <DiagnosticSeverity.WARNING: 1>, 'NOTE': <DiagnosticSeverity.NOTE: 2>, 'REMARK': <DiagnosticSeverity.REMARK: 3>}
     def __eq__(self, other: Any) -> bool: ...
     def __getstate__(self) -> int: ...
@@ -1455,7 +1449,7 @@ class Dialects:
 class DictAttr(Attribute):
     static_typeid: ClassVar[TypeID]
     @staticmethod
-    def get(value: Dict = {}, context: Optional[Context] = None) -> DictAttr:
+    def get(value: dict = {}, context: Context | None = None) -> DictAttr:
         """
         Gets an uniqued Dict attribute
         """
@@ -1486,7 +1480,7 @@ class FloatType(Type):
 class F16Type(FloatType):
     static_typeid: ClassVar[TypeID]
     @staticmethod
-    def get(context: Optional[Context] = None) -> F16Type:
+    def get(context: Context | None = None) -> F16Type:
         """
         Create a f16 type.
         """
@@ -1499,7 +1493,7 @@ class F16Type(FloatType):
 class F32Type(FloatType):
     static_typeid: ClassVar[TypeID]
     @staticmethod
-    def get(context: Optional[Context] = None) -> F32Type:
+    def get(context: Context | None = None) -> F32Type:
         """
         Create a f32 type.
         """
@@ -1512,7 +1506,7 @@ class F32Type(FloatType):
 class F64Type(FloatType):
     static_typeid: ClassVar[TypeID]
     @staticmethod
-    def get(context: Optional[Context] = None) -> F64Type:
+    def get(context: Context | None = None) -> F64Type:
         """
         Create a f64 type.
         """
@@ -1524,7 +1518,7 @@ class F64Type(FloatType):
 
 class FlatSymbolRefAttr(Attribute):
     @staticmethod
-    def get(value: str, context: Optional[Context] = None) -> FlatSymbolRefAttr:
+    def get(value: str, context: Context | None = None) -> FlatSymbolRefAttr:
         """
         Gets a uniqued FlatSymbolRef attribute
         """
@@ -1546,7 +1540,7 @@ class FlatSymbolRefAttr(Attribute):
 class Float4E2M1FNType(FloatType):
     static_typeid: ClassVar[TypeID]
     @staticmethod
-    def get(context: Optional[Context] = None) -> Float4E2M1FNType:
+    def get(context: Context | None = None) -> Float4E2M1FNType:
         """
         Create a float4_e2m1fn type.
         """
@@ -1559,7 +1553,7 @@ class Float4E2M1FNType(FloatType):
 class Float6E2M3FNType(FloatType):
     static_typeid: ClassVar[TypeID]
     @staticmethod
-    def get(context: Optional[Context] = None) -> Float6E2M3FNType:
+    def get(context: Context | None = None) -> Float6E2M3FNType:
         """
         Create a float6_e2m3fn type.
         """
@@ -1572,7 +1566,7 @@ class Float6E2M3FNType(FloatType):
 class Float6E3M2FNType(FloatType):
     static_typeid: ClassVar[TypeID]
     @staticmethod
-    def get(context: Optional[Context] = None) -> Float6E3M2FNType:
+    def get(context: Context | None = None) -> Float6E3M2FNType:
         """
         Create a float6_e3m2fn type.
         """
@@ -1585,7 +1579,7 @@ class Float6E3M2FNType(FloatType):
 class Float8E3M4Type(FloatType):
     static_typeid: ClassVar[TypeID]
     @staticmethod
-    def get(context: Optional[Context] = None) -> Float8E3M4Type:
+    def get(context: Context | None = None) -> Float8E3M4Type:
         """
         Create a float8_e3m4 type.
         """
@@ -1598,7 +1592,7 @@ class Float8E3M4Type(FloatType):
 class Float8E4M3B11FNUZType(FloatType):
     static_typeid: ClassVar[TypeID]
     @staticmethod
-    def get(context: Optional[Context] = None) -> Float8E4M3B11FNUZType:
+    def get(context: Context | None = None) -> Float8E4M3B11FNUZType:
         """
         Create a float8_e4m3b11fnuz type.
         """
@@ -1611,7 +1605,7 @@ class Float8E4M3B11FNUZType(FloatType):
 class Float8E4M3FNType(FloatType):
     static_typeid: ClassVar[TypeID]
     @staticmethod
-    def get(context: Optional[Context] = None) -> Float8E4M3FNType:
+    def get(context: Context | None = None) -> Float8E4M3FNType:
         """
         Create a float8_e4m3fn type.
         """
@@ -1624,7 +1618,7 @@ class Float8E4M3FNType(FloatType):
 class Float8E4M3FNUZType(FloatType):
     static_typeid: ClassVar[TypeID]
     @staticmethod
-    def get(context: Optional[Context] = None) -> Float8E4M3FNUZType:
+    def get(context: Context | None = None) -> Float8E4M3FNUZType:
         """
         Create a float8_e4m3fnuz type.
         """
@@ -1637,7 +1631,7 @@ class Float8E4M3FNUZType(FloatType):
 class Float8E4M3Type(FloatType):
     static_typeid: ClassVar[TypeID]
     @staticmethod
-    def get(context: Optional[Context] = None) -> Float8E4M3Type:
+    def get(context: Context | None = None) -> Float8E4M3Type:
         """
         Create a float8_e4m3 type.
         """
@@ -1650,7 +1644,7 @@ class Float8E4M3Type(FloatType):
 class Float8E5M2FNUZType(FloatType):
     static_typeid: ClassVar[TypeID]
     @staticmethod
-    def get(context: Optional[Context] = None) -> Float8E5M2FNUZType:
+    def get(context: Context | None = None) -> Float8E5M2FNUZType:
         """
         Create a float8_e5m2fnuz type.
         """
@@ -1663,7 +1657,7 @@ class Float8E5M2FNUZType(FloatType):
 class Float8E5M2Type(FloatType):
     static_typeid: ClassVar[TypeID]
     @staticmethod
-    def get(context: Optional[Context] = None) -> Float8E5M2Type:
+    def get(context: Context | None = None) -> Float8E5M2Type:
         """
         Create a float8_e5m2 type.
         """
@@ -1676,17 +1670,17 @@ class Float8E5M2Type(FloatType):
 class FloatAttr(Attribute):
     static_typeid: ClassVar[TypeID]
     @staticmethod
-    def get(type: Type, value: float, loc: Optional[Location] = None) -> FloatAttr:
+    def get(type: Type, value: float, loc: Location | None = None) -> FloatAttr:
         """
         Gets an uniqued float point attribute associated to a type
         """
     @staticmethod
-    def get_f32(value: float, context: Optional[Context] = None) -> FloatAttr:
+    def get_f32(value: float, context: Context | None = None) -> FloatAttr:
         """
         Gets an uniqued float point attribute associated to a f32 type
         """
     @staticmethod
-    def get_f64(value: float, context: Optional[Context] = None) -> FloatAttr:
+    def get_f64(value: float, context: Context | None = None) -> FloatAttr:
         """
         Gets an uniqued float point attribute associated to a f64 type
         """
@@ -1710,7 +1704,7 @@ class FloatAttr(Attribute):
 class FloatTF32Type(FloatType):
     static_typeid: ClassVar[TypeID]
     @staticmethod
-    def get(context: Optional[Context] = None) -> FloatTF32Type:
+    def get(context: Context | None = None) -> FloatTF32Type:
         """
         Create a tf32 type.
         """
@@ -1724,7 +1718,7 @@ class FunctionType(Type):
     static_typeid: ClassVar[TypeID]
     @staticmethod
     def get(
-        inputs: List[Type], results: List[Type], context: Optional[Context] = None
+        inputs: list[Type], results: list[Type], context: Context | None = None
     ) -> FunctionType:
         """
         Gets a FunctionType from a List of input and result types
@@ -1733,12 +1727,12 @@ class FunctionType(Type):
     def isinstance(other: Type) -> bool: ...
     def __init__(self, cast_from_type: Type) -> None: ...
     @property
-    def inputs(self) -> List:
+    def inputs(self) -> list:
         """
         Returns the List of input types in the FunctionType.
         """
     @property
-    def results(self) -> List:
+    def results(self) -> list:
         """
         Returns the List of result types in the FunctionType.
         """
@@ -1748,7 +1742,7 @@ class FunctionType(Type):
 class IndexType(Type):
     static_typeid: ClassVar[TypeID]
     @staticmethod
-    def get(context: Optional[Context] = None) -> IndexType:
+    def get(context: Context | None = None) -> IndexType:
         """
         Create a index type.
         """
@@ -1759,7 +1753,7 @@ class IndexType(Type):
     def typeid(self) -> TypeID: ...
 
 class InferShapedTypeOpInterface:
-    def __init__(self, object: object, context: Optional[Context] = None) -> None:
+    def __init__(self, object: object, context: Context | None = None) -> None:
         """
         Creates an interface from a given operation/opview object or from a
         subclass of OpView. Raises ValueError if the operation does not implement the
@@ -1767,13 +1761,13 @@ class InferShapedTypeOpInterface:
         """
     def inferReturnTypeComponents(
         self,
-        operands: Optional[List] = None,
-        attributes: Optional[Attribute] = None,
+        operands: list | None = None,
+        attributes: Attribute | None = None,
         properties=None,
-        regions: Optional[List[Region]] = None,
-        context: Optional[Context] = None,
-        loc: Optional[Location] = None,
-    ) -> List[ShapedTypeComponents]:
+        regions: list[Region] | None = None,
+        context: Context | None = None,
+        loc: Location | None = None,
+    ) -> list[ShapedTypeComponents]:
         """
         Given the arguments required to build an operation, attempts to infer
         its return shaped type components. Raises ValueError on failure.
@@ -1791,7 +1785,7 @@ class InferShapedTypeOpInterface:
         """
 
 class InferTypeOpInterface:
-    def __init__(self, object: object, context: Optional[Context] = None) -> None:
+    def __init__(self, object: object, context: Context | None = None) -> None:
         """
         Creates an interface from a given operation/opview object or from a
         subclass of OpView. Raises ValueError if the operation does not implement the
@@ -1799,13 +1793,13 @@ class InferTypeOpInterface:
         """
     def inferReturnTypes(
         self,
-        operands: Optional[List] = None,
-        attributes: Optional[Attribute] = None,
+        operands: list | None = None,
+        attributes: Attribute | None = None,
         properties=None,
-        regions: Optional[List[Region]] = None,
-        context: Optional[Context] = None,
-        loc: Optional[Location] = None,
-    ) -> List[Type]:
+        regions: list[Region] | None = None,
+        context: Context | None = None,
+        loc: Location | None = None,
+    ) -> list[Type]:
         """
         Given the arguments required to build an operation, attempts to infer
         its return types. Raises ValueError on failure.
@@ -1856,7 +1850,7 @@ class InsertionPoint:
         Returns the block that this InsertionPoint points to.
         """
     @property
-    def ref_operation(self) -> Optional[_OperationBase]:
+    def ref_operation(self) -> _OperationBase | None:
         """
         The reference operation before which new operations are inserted, or None if the insertion point is at the end of the block
         """
@@ -1890,13 +1884,13 @@ class IntegerSet:
     def get(
         num_dims: int,
         num_symbols: int,
-        exprs: List,
-        eq_flags: List[bool],
-        context: Optional[Context] = None,
+        exprs: list,
+        eq_flags: list[bool],
+        context: Context | None = None,
     ) -> IntegerSet: ...
     @staticmethod
     def get_empty(
-        num_dims: int, num_symbols: int, context: Optional[Context] = None
+        num_dims: int, num_symbols: int, context: Context | None = None
     ) -> IntegerSet: ...
     def _CAPICreate(self) -> IntegerSet: ...
     @overload
@@ -1910,8 +1904,8 @@ class IntegerSet:
         """
     def get_replaced(
         self,
-        dim_exprs: List,
-        symbol_exprs: List,
+        dim_exprs: list,
+        symbol_exprs: list,
         num_result_dims: int,
         num_result_symbols: int,
     ) -> IntegerSet: ...
@@ -1958,7 +1952,7 @@ class IntegerSetConstraint:
 
 class IntegerSetConstraintList:
     def __init__(self, *args, **kwargs) -> None: ...
-    def __add__(self, arg0: IntegerSetConstraintList) -> List[IntegerSetConstraint]: ...
+    def __add__(self, arg0: IntegerSetConstraintList) -> list[IntegerSetConstraint]: ...
     @overload
     def __getitem__(self, arg0: int) -> IntegerSetConstraint: ...
     @overload
@@ -1968,17 +1962,17 @@ class IntegerSetConstraintList:
 class IntegerType(Type):
     static_typeid: ClassVar[TypeID]
     @staticmethod
-    def get_signed(width: int, context: Optional[Context] = None) -> IntegerType:
+    def get_signed(width: int, context: Context | None = None) -> IntegerType:
         """
         Create a signed integer type
         """
     @staticmethod
-    def get_signless(width: int, context: Optional[Context] = None) -> IntegerType:
+    def get_signless(width: int, context: Context | None = None) -> IntegerType:
         """
         Create a signless integer type
         """
     @staticmethod
-    def get_unsigned(width: int, context: Optional[Context] = None) -> IntegerType:
+    def get_unsigned(width: int, context: Context | None = None) -> IntegerType:
         """
         Create an unsigned integer type
         """
@@ -2013,28 +2007,28 @@ class Location:
     __hash__: ClassVar[None] = None
     @staticmethod
     def callsite(
-        callee: Location, frames: Sequence[Location], context: Optional[Context] = None
+        callee: Location, frames: Sequence[Location], context: Context | None = None
     ) -> Location:
         """
         Gets a Location representing a caller and callsite
         """
     @staticmethod
     def file(
-        filename: str, line: int, col: int, context: Optional[Context] = None
+        filename: str, line: int, col: int, context: Context | None = None
     ) -> Location:
         """
         Gets a Location representing a file, line and column
         """
     @staticmethod
-    def from_attr(attribute: Attribute, context: Optional[Context] = None) -> Location:
+    def from_attr(attribute: Attribute, context: Context | None = None) -> Location:
         """
         Gets a Location from a LocationAttr
         """
     @staticmethod
     def fused(
         locations: Sequence[Location],
-        metadata: Optional[Attribute] = None,
-        context: Optional[Context] = None,
+        metadata: Attribute | None = None,
+        context: Context | None = None,
     ) -> Location:
         """
         Gets a Location representing a fused location with optional metadata
@@ -2042,14 +2036,14 @@ class Location:
     @staticmethod
     def name(
         name: str,
-        childLoc: Optional[Location] = None,
-        context: Optional[Context] = None,
+        childLoc: Location | None = None,
+        context: Context | None = None,
     ) -> Location:
         """
         Gets a Location representing a named location with optional child location
         """
     @staticmethod
-    def unknown(context: Optional[Context] = None) -> Location:
+    def unknown(context: Context | None = None) -> Location:
         """
         Gets a Location representing an unknown location
         """
@@ -2081,11 +2075,11 @@ class MemRefType(ShapedType):
     static_typeid: ClassVar[TypeID]
     @staticmethod
     def get(
-        shape: List[int],
+        shape: list[int],
         element_type: Type,
         layout: Attribute = None,
         memory_space: Attribute = None,
-        loc: Optional[Location] = None,
+        loc: Location | None = None,
     ) -> MemRefType:
         """
         Create a memref type
@@ -2104,7 +2098,7 @@ class MemRefType(ShapedType):
         The layout of the MemRef type.
         """
     @property
-    def memory_space(self) -> Optional[Attribute]:
+    def memory_space(self) -> Attribute | None:
         """
         Returns the memory space of the given MemRef type.
         """
@@ -2117,12 +2111,12 @@ class MemRefType(ShapedType):
 
 class Module:
     @staticmethod
-    def create(loc: Optional[Location] = None) -> Module:
+    def create(loc: Location | None = None) -> Module:
         """
         Creates an empty module
         """
     @staticmethod
-    def parse(asm: str | bytes, context: Optional[Context] = None) -> Module:
+    def parse(asm: str | bytes, context: Context | None = None) -> Module:
         """
         Parses a module's assembly format from a string.
 
@@ -2163,7 +2157,7 @@ class Module:
 
 class MLIRError(Exception):
     def __init__(
-        self, message: str, error_diagnostics: List[DiagnosticInfo]
+        self, message: str, error_diagnostics: list[DiagnosticInfo]
     ) -> None: ...
 
 class NamedAttribute:
@@ -2181,7 +2175,7 @@ class NamedAttribute:
 class NoneType(Type):
     static_typeid: ClassVar[TypeID]
     @staticmethod
-    def get(context: Optional[Context] = None) -> NoneType:
+    def get(context: Context | None = None) -> NoneType:
         """
         Create a none type.
         """
@@ -2212,7 +2206,7 @@ class OpOperandIterator:
     def __next__(self) -> OpOperand: ...
 
 class OpOperandList:
-    def __add__(self, arg0: OpOperandList) -> List[Value]: ...
+    def __add__(self, arg0: OpOperandList) -> list[Value]: ...
     @overload
     def __getitem__(self, arg0: int) -> Value: ...
     @overload
@@ -2232,7 +2226,7 @@ class OpResult(Value):
     def result_number(self) -> int: ...
 
 class OpResultList:
-    def __add__(self, arg0: OpResultList) -> List[OpResult]: ...
+    def __add__(self, arg0: OpResultList) -> list[OpResult]: ...
     @overload
     def __getitem__(self, arg0: int) -> OpResult: ...
     @overload
@@ -2241,10 +2235,10 @@ class OpResultList:
     @property
     def owner(self) -> _OperationBase: ...
     @property
-    def types(self) -> List[Type]: ...
+    def types(self) -> list[Type]: ...
 
 class OpSuccessors:
-    def __add__(self, arg0: OpSuccessors) -> List[Block]: ...
+    def __add__(self, arg0: OpSuccessors) -> list[Block]: ...
     @overload
     def __getitem__(self, arg0: int) -> Block: ...
     @overload
@@ -2260,13 +2254,13 @@ class OpView(_OperationBase):
     @classmethod
     def build_generic(
         cls: _Type[_TOperation],
-        results: Optional[Sequence[Type]] = None,
-        operands: Optional[Sequence[Value]] = None,
-        attributes: Optional[Dict[str, Attribute]] = None,
-        successors: Optional[Sequence[Block]] = None,
-        regions: Optional[int] = None,
-        loc: Optional[Location] = None,
-        ip: Optional[InsertionPoint] = None,
+        results: Sequence[Type] | None = None,
+        operands: Sequence[Value] | None = None,
+        attributes: dict[str, Attribute] | None = None,
+        successors: Sequence[Block] | None = None,
+        regions: int | None = None,
+        loc: Location | None = None,
+        ip: InsertionPoint | None = None,
     ) -> _TOperation:
         """
         Builds a specific, generated OpView based on class level attributes.
@@ -2277,7 +2271,7 @@ class OpView(_OperationBase):
         source: str | bytes,
         *,
         source_name: str = "",
-        context: Optional[Context] = None,
+        context: Context | None = None,
     ) -> _TOperation:
         """
         Parses a specific, generated OpView based on class level attributes
@@ -2300,7 +2294,7 @@ class OpaqueAttr(Attribute):
         dialect_namespace: str,
         buffer: Buffer,
         type: Type,
-        context: Optional[Context] = None,
+        context: Context | None = None,
     ) -> OpaqueAttr:
         """
         Gets an Opaque attribute.
@@ -2327,7 +2321,7 @@ class OpaqueType(Type):
     static_typeid: ClassVar[TypeID]
     @staticmethod
     def get(
-        dialect_namespace: str, buffer: str, context: Optional[Context] = None
+        dialect_namespace: str, buffer: str, context: Context | None = None
     ) -> OpaqueType:
         """
         Create an unregistered (opaque) dialect type.
@@ -2353,13 +2347,13 @@ class Operation(_OperationBase):
     @staticmethod
     def create(
         name: str,
-        results: Optional[Sequence[Type]] = None,
-        operands: Optional[Sequence[Value]] = None,
-        attributes: Optional[Dict[str, Attribute]] = None,
-        successors: Optional[Sequence[Block]] = None,
+        results: Sequence[Type] | None = None,
+        operands: Sequence[Value] | None = None,
+        attributes: dict[str, Attribute] | None = None,
+        successors: Sequence[Block] | None = None,
         regions: int = 0,
-        loc: Optional[Location] = None,
-        ip: Optional[InsertionPoint] = None,
+        loc: Location | None = None,
+        ip: InsertionPoint | None = None,
         infer_type: bool = False,
     ) -> Operation:
         """
@@ -2382,7 +2376,7 @@ class Operation(_OperationBase):
         """
     @staticmethod
     def parse(
-        source: str | bytes, *, source_name: str = "", context: Optional[Context] = None
+        source: str | bytes, *, source_name: str = "", context: Context | None = None
     ) -> Operation:
         """
         Parses an operation. Supports both text assembly format and binary bytecode format.
@@ -2413,10 +2407,10 @@ class RankedTensorType(ShapedType):
     static_typeid: ClassVar[TypeID]
     @staticmethod
     def get(
-        shape: List[int],
+        shape: list[int],
         element_type: Type,
-        encoding: Optional[Attribute] = None,
-        loc: Optional[Location] = None,
+        encoding: Attribute | None = None,
+        loc: Location | None = None,
     ) -> RankedTensorType:
         """
         Create a ranked tensor type
@@ -2425,7 +2419,7 @@ class RankedTensorType(ShapedType):
     def isinstance(other: Type) -> bool: ...
     def __init__(self, cast_from_type: Type) -> None: ...
     @property
-    def encoding(self) -> Optional[Attribute]: ...
+    def encoding(self) -> Attribute | None: ...
     @property
     def typeid(self) -> TypeID: ...
 
@@ -2511,7 +2505,7 @@ class ShapedType(Type):
         Returns the rank of the given ranked shaped type.
         """
     @property
-    def shape(self) -> List[int]:
+    def shape(self) -> list[int]:
         """
         Returns the shape of the ranked shaped type as a List of integers.
         """
@@ -2529,14 +2523,14 @@ class ShapedTypeComponents:
         """
     @staticmethod
     @overload
-    def get(shape: List, element_type: Type) -> ShapedTypeComponents:
+    def get(shape: list, element_type: Type) -> ShapedTypeComponents:
         """
         Create a ranked shaped type components object.
         """
     @staticmethod
     @overload
     def get(
-        shape: List, element_type: Type, attribute: Attribute
+        shape: list, element_type: Type, attribute: Attribute
     ) -> ShapedTypeComponents:
         """
         Create a ranked shaped type components object with attribute.
@@ -2557,7 +2551,7 @@ class ShapedTypeComponents:
         Returns the rank of the given ranked shaped type components. If the shaped type components does not have a rank, None is returned.
         """
     @property
-    def shape(self) -> List[int]:
+    def shape(self) -> list[int]:
         """
         Returns the shape of the ranked shaped type components as a List of integers. Returns none if the shaped type component does not have a rank.
         """
@@ -2566,14 +2560,14 @@ class StridedLayoutAttr(Attribute):
     static_typeid: ClassVar[TypeID]
     @staticmethod
     def get(
-        offset: int, strides: List[int], context: Optional[Context] = None
+        offset: int, strides: list[int], context: Context | None = None
     ) -> StridedLayoutAttr:
         """
         Gets a strided layout attribute.
         """
     @staticmethod
     def get_fully_dynamic(
-        rank: int, context: Optional[Context] = None
+        rank: int, context: Context | None = None
     ) -> StridedLayoutAttr:
         """
         Gets a strided layout attribute with dynamic offset and strides of a given rank.
@@ -2587,7 +2581,7 @@ class StridedLayoutAttr(Attribute):
         Returns the value of the float point attribute
         """
     @property
-    def strides(self) -> List[int]:
+    def strides(self) -> list[int]:
         """
         Returns the value of the float point attribute
         """
@@ -2599,7 +2593,7 @@ class StridedLayoutAttr(Attribute):
 class StringAttr(Attribute):
     static_typeid: ClassVar[TypeID]
     @staticmethod
-    def get(value: str | bytes, context: Optional[Context] = None) -> StringAttr:
+    def get(value: str | bytes, context: Context | None = None) -> StringAttr:
         """
         Gets a uniqued string attribute
         """
@@ -2628,7 +2622,7 @@ class StringAttr(Attribute):
 
 class SymbolRefAttr(Attribute):
     @staticmethod
-    def get(symbols: List[str], context: Optional[Context] = None) -> Attribute:
+    def get(symbols: list[str], context: Context | None = None) -> Attribute:
         """
         Gets a uniqued SymbolRef attribute from a List of symbol names
         """
@@ -2642,7 +2636,7 @@ class SymbolRefAttr(Attribute):
     @property
     def typeid(self) -> TypeID: ...
     @property
-    def value(self) -> List[str]:
+    def value(self) -> list[str]:
         """
         Returns the value of the SymbolRef attribute as a List[str]
         """
@@ -2676,7 +2670,7 @@ class SymbolTable:
 class TupleType(Type):
     static_typeid: ClassVar[TypeID]
     @staticmethod
-    def get_tuple(elements: List[Type], context: Optional[Context] = None) -> TupleType:
+    def get_tuple(elements: list[Type], context: Context | None = None) -> TupleType:
         """
         Create a Tuple type
         """
@@ -2698,7 +2692,7 @@ class TupleType(Type):
 class TypeAttr(Attribute):
     static_typeid: ClassVar[TypeID]
     @staticmethod
-    def get(value: Type, context: Optional[Context] = None) -> TypeAttr:
+    def get(value: Type, context: Context | None = None) -> TypeAttr:
         """
         Gets a uniqued Type attribute
         """
@@ -2725,7 +2719,7 @@ class TypeID:
 class UnitAttr(Attribute):
     static_typeid: ClassVar[TypeID]
     @staticmethod
-    def get(context: Optional[Context] = None) -> UnitAttr:
+    def get(context: Context | None = None) -> UnitAttr:
         """
         Create a Unit attribute.
         """
@@ -2741,7 +2735,7 @@ class UnrankedMemRefType(ShapedType):
     static_typeid: ClassVar[TypeID]
     @staticmethod
     def get(
-        element_type: Type, memory_space: Attribute, loc: Optional[Location] = None
+        element_type: Type, memory_space: Attribute, loc: Location | None = None
     ) -> UnrankedMemRefType:
         """
         Create a unranked memref type
@@ -2750,7 +2744,7 @@ class UnrankedMemRefType(ShapedType):
     def isinstance(other: Type) -> bool: ...
     def __init__(self, cast_from_type: Type) -> None: ...
     @property
-    def memory_space(self) -> Optional[Attribute]:
+    def memory_space(self) -> Attribute | None:
         """
         Returns the memory space of the given Unranked MemRef type.
         """
@@ -2760,7 +2754,7 @@ class UnrankedMemRefType(ShapedType):
 class UnrankedTensorType(ShapedType):
     static_typeid: ClassVar[TypeID]
     @staticmethod
-    def get(element_type: Type, loc: Optional[Location] = None) -> UnrankedTensorType:
+    def get(element_type: Type, loc: Location | None = None) -> UnrankedTensorType:
         """
         Create a unranked tensor type
         """
@@ -2774,12 +2768,12 @@ class VectorType(ShapedType):
     static_typeid: ClassVar[TypeID]
     @staticmethod
     def get(
-        shape: List[int],
+        shape: list[int],
         element_type: Type,
         *,
-        scalable: Optional[List] = None,
-        scalable_dims: Optional[List[int]] = None,
-        loc: Optional[Location] = None,
+        scalable: list | None = None,
+        scalable_dims: list[int] | None = None,
+        loc: Location | None = None,
     ) -> VectorType:
         """
         Create a vector type
@@ -2790,7 +2784,7 @@ class VectorType(ShapedType):
     @property
     def scalable(self) -> bool: ...
     @property
-    def scalable_dims(self) -> List[bool]: ...
+    def scalable_dims(self) -> list[bool]: ...
     @property
     def typeid(self) -> TypeID: ...
 
diff --git a/mlir/python/mlir/_mlir_libs/_mlir/passmanager.pyi b/mlir/python/mlir/_mlir_libs/_mlir/passmanager.pyi
index 5d115e8222d730..229979ae33608c 100644
--- a/mlir/python/mlir/_mlir_libs/_mlir/passmanager.pyi
+++ b/mlir/python/mlir/_mlir_libs/_mlir/passmanager.pyi
@@ -4,7 +4,6 @@
 #   * Relative imports for cross-module references.
 #   * Add __all__
 
-from typing import Any, Optional
 
 from . import ir as _ir
 
@@ -13,7 +12,7 @@ __all__ = [
 ]
 
 class PassManager:
-    def __init__(self, context: Optional[_ir.Context] = None) -> None: ...
+    def __init__(self, context: _ir.Context | None = None) -> None: ...
     def _CAPICreate(self) -> object: ...
     def _testing_release(self) -> None: ...
     def enable_ir_printing(
@@ -26,7 +25,7 @@ class PassManager:
     ) -> None: ...
     def enable_verifier(self, enable: bool) -> None: ...
     @staticmethod
-    def parse(pipeline: str, context: Optional[_ir.Context] = None) -> PassManager: ...
+    def parse(pipeline: str, context: _ir.Context | None = None) -> PassManager: ...
     def run(self, module: _ir._OperationBase) -> None: ...
     @property
     def _CAPIPtr(self) -> object: ...
diff --git a/mlir/python/mlir/_mlir_libs/_mlirExecutionEngine.pyi b/mlir/python/mlir/_mlir_libs/_mlirExecutionEngine.pyi
index 893dab8a431fd1..58d453d2b2d37c 100644
--- a/mlir/python/mlir/_mlir_libs/_mlirExecutionEngine.pyi
+++ b/mlir/python/mlir/_mlir_libs/_mlirExecutionEngine.pyi
@@ -4,7 +4,7 @@
 #   * Relative imports for cross-module references.
 #   * Add __all__
 
-from typing import List, Sequence
+from collections.abc import Sequence
 
 from ._mlir import ir as _ir
 

>From 3bfd49794493001008efb42388e76bb669aba656 Mon Sep 17 00:00:00 2001
From: Sergei Lebedev <slebedev at google.com>
Date: Mon, 30 Sep 2024 10:41:37 +0000
Subject: [PATCH 3/3] Use the built in `type` instead of `typing.Type`

---
 mlir/python/mlir/_mlir_libs/_mlir/ir.pyi | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/mlir/python/mlir/_mlir_libs/_mlir/ir.pyi b/mlir/python/mlir/_mlir_libs/_mlir/ir.pyi
index aadbb781c2c414..41ed84e0467254 100644
--- a/mlir/python/mlir/_mlir_libs/_mlir/ir.pyi
+++ b/mlir/python/mlir/_mlir_libs/_mlir/ir.pyi
@@ -44,16 +44,9 @@ from __future__ import annotations
 
 import abc
 import collections
-import io
-from typing import (
-    Any,
-    ClassVar,
-    Type as _Type,
-    TypeVar,
-)
 from collections.abc import Callable, Sequence
-
-from typing import overload
+import io
+from typing import Any, ClassVar, TypeVar, overload
 
 __all__ = [
     "AffineAddExpr",
@@ -2253,7 +2246,7 @@ class OpView(_OperationBase):
     def __init__(self, operation: _OperationBase) -> None: ...
     @classmethod
     def build_generic(
-        cls: _Type[_TOperation],
+        cls: type[_TOperation],
         results: Sequence[Type] | None = None,
         operands: Sequence[Value] | None = None,
         attributes: dict[str, Attribute] | None = None,
@@ -2267,7 +2260,7 @@ class OpView(_OperationBase):
         """
     @classmethod
     def parse(
-        cls: _Type[_TOperation],
+        cls: type[_TOperation],
         source: str | bytes,
         *,
         source_name: str = "",



More information about the Mlir-commits mailing list