[Mlir-commits] [mlir] Slightly improved ir.pyi type annotations (PR #76728)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Jan 2 07:52:45 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Sergei Lebedev (superbobry)

<details>
<summary>Changes</summary>

* Replaced `Any` with static types where appropriate
* Removed undocumented `__str__` and `__repr__` -- these are always defined via `object`

---
Full diff: https://github.com/llvm/llvm-project/pull/76728.diff


1 Files Affected:

- (modified) mlir/python/mlir/_mlir_libs/_mlir/ir.pyi (+10-74) 


``````````diff
diff --git a/mlir/python/mlir/_mlir_libs/_mlir/ir.pyi b/mlir/python/mlir/_mlir_libs/_mlir/ir.pyi
index fa591e5f142d9b..57a85990f9bcf5 100644
--- a/mlir/python/mlir/_mlir_libs/_mlir/ir.pyi
+++ b/mlir/python/mlir/_mlir_libs/_mlir/ir.pyi
@@ -460,11 +460,9 @@ class AffineExpr:
     @overload
     def __mul__(self, arg0: int) -> AffineMulExpr: ...
     def __radd__(self, arg0: int) -> AffineAddExpr: ...
-    def __repr__(self) -> str: ...
     def __rmod__(self, arg0: int) -> AffineModExpr: ...
     def __rmul__(self, arg0: int) -> AffineMulExpr: ...
     def __rsub__(self, arg0: int) -> AffineAddExpr: ...
-    def __str__(self) -> str: ...
     @overload
     def __sub__(self, arg0: AffineExpr) -> AffineAddExpr: ...
     @overload
@@ -495,7 +493,6 @@ class Attribute:
         """
         Casts the passed attribute to the generic Attribute
         """
-    def __repr__(self) -> str: ...
     def __str__(self) -> str:
         """
         Returns the assembly form of the Attribute.
@@ -541,7 +538,6 @@ class Type:
         """
         Casts the passed type to the generic Type
         """
-    def __repr__(self) -> str: ...
     def __str__(self) -> str:
         """
         Returns the assembly form of the type.
@@ -710,8 +706,6 @@ class AffineMap:
     @overload
     def __eq__(self, arg0: object) -> bool: ...
     def __hash__(self) -> int: ...
-    def __repr__(self) -> str: ...
-    def __str__(self) -> str: ...
     def dump(self) -> None:
         """
         Dumps a debug representation of the object to stderr.
@@ -756,7 +750,6 @@ class AffineMapAttr(Attribute):
     @staticmethod
     def isinstance(other: Attribute) -> bool: ...
     def __init__(self, cast_from_attr: Attribute) -> None: ...
-    def __repr__(self) -> str: ...
     @property
     def type(self) -> Type: ...
     @property
@@ -801,7 +794,6 @@ class ArrayAttr(Attribute):
         self,
     ) -> ArrayAttributeIterator: ...
     def __len__(self) -> int: ...
-    def __repr__(self) -> str: ...
     @property
     def type(self) -> Type: ...
     @property
@@ -840,7 +832,6 @@ class BF16Type(Type):
     @staticmethod
     def isinstance(other: Type) -> bool: ...
     def __init__(self, cast_from_type: Type) -> None: ...
-    def __repr__(self) -> str: ...
     @property
     def typeid(self) -> TypeID: ...
 
@@ -951,7 +942,6 @@ class BoolAttr(Attribute):
         Converts the value of the bool attribute to a Python bool
         """
     def __init__(self, cast_from_attr: Attribute) -> None: ...
-    def __repr__(self) -> str: ...
     @property
     def static_typeid(self) -> TypeID: ...
     @property
@@ -974,7 +964,6 @@ class ComplexType(Type):
     @staticmethod
     def isinstance(other: Type) -> bool: ...
     def __init__(self, cast_from_type: Type) -> None: ...
-    def __repr__(self) -> str: ...
     @property
     def element_type(self) -> Type:
         """
@@ -989,7 +978,7 @@ class Context:
     @staticmethod
     def _get_live_count() -> int: ...
     def _CAPICreate(self) -> object: ...
-    def __enter__(self) -> Any: ...
+    def __enter__(self) -> Context: ...
     def __exit__(self, arg0: Any, arg1: Any, arg2: Any) -> None: ...
     def __init__(self) -> None: ...
     def _clear_live_operations(self) -> int: ...
@@ -1040,7 +1029,6 @@ class DenseBoolArrayAttr(Attribute):
         self,
     ) -> DenseBoolArrayIterator: ...
     def __len__(self) -> int: ...
-    def __repr__(self) -> str: ...
     @property
     def static_typeid(self) -> TypeID: ...
     @property
@@ -1111,7 +1099,6 @@ class DenseElementsAttr(Attribute):
     def isinstance(other: Attribute) -> bool: ...
     def __init__(self, cast_from_attr: Attribute) -> None: ...
     def __len__(self) -> int: ...
-    def __repr__(self) -> str: ...
     def get_splat_value(self) -> Attribute: ...
     @property
     def is_splat(self) -> bool: ...
@@ -1139,7 +1126,6 @@ class DenseF32ArrayAttr(Attribute):
         self,
     ) -> DenseF32ArrayIterator: ...
     def __len__(self) -> int: ...
-    def __repr__(self) -> str: ...
     @property
     def static_typeid(self) -> TypeID: ...
     @property
@@ -1168,7 +1154,6 @@ class DenseF64ArrayAttr(Attribute):
         self,
     ) -> DenseF64ArrayIterator: ...
     def __len__(self) -> int: ...
-    def __repr__(self) -> str: ...
     @property
     def static_typeid(self) -> TypeID: ...
     @property
@@ -1185,7 +1170,6 @@ class DenseFPElementsAttr(DenseElementsAttr):
     def isinstance(other: Attribute) -> bool: ...
     def __getitem__(self, arg0: int) -> float: ...
     def __init__(self, cast_from_attr: Attribute) -> None: ...
-    def __repr__(self) -> str: ...
     @property
     def static_typeid(self) -> TypeID: ...
     @property
@@ -1208,7 +1192,6 @@ class DenseI16ArrayAttr(Attribute):
         self,
     ) -> DenseI16ArrayIterator: ...
     def __len__(self) -> int: ...
-    def __repr__(self) -> str: ...
     @property
     def static_typeid(self) -> TypeID: ...
     @property
@@ -1235,7 +1218,6 @@ class DenseI32ArrayAttr(Attribute):
         self,
     ) -> DenseI32ArrayIterator: ...
     def __len__(self) -> int: ...
-    def __repr__(self) -> str: ...
     @property
     def static_typeid(self) -> TypeID: ...
     @property
@@ -1262,7 +1244,6 @@ class DenseI64ArrayAttr(Attribute):
         self,
     ) -> DenseI16ArrayIterator: ...
     def __len__(self) -> int: ...
-    def __repr__(self) -> str: ...
     @property
     def static_typeid(self) -> TypeID: ...
     @property
@@ -1289,7 +1270,6 @@ class DenseI8ArrayAttr(Attribute):
         self,
     ) -> DenseI8ArrayIterator: ...
     def __len__(self) -> int: ...
-    def __repr__(self) -> str: ...
     @property
     def static_typeid(self) -> TypeID: ...
     @property
@@ -1306,7 +1286,6 @@ class DenseIntElementsAttr(DenseElementsAttr):
     def isinstance(other: Attribute) -> bool: ...
     def __getitem__(self, arg0: int) -> int: ...
     def __init__(self, cast_from_attr: Attribute) -> None: ...
-    def __repr__(self) -> str: ...
     @property
     def static_typeid(self) -> TypeID: ...
     @property
@@ -1352,7 +1331,6 @@ class DenseResourceElementsAttr(Attribute):
     @staticmethod
     def isinstance(other: Attribute) -> bool: ...
     def __init__(self, cast_from_attr: Attribute) -> None: ...
-    def __repr__(self) -> str: ...
     @property
     def static_typeid(self) -> TypeID: ...
     @property
@@ -1361,7 +1339,6 @@ class DenseResourceElementsAttr(Attribute):
     def typeid(self) -> TypeID: ...
 
 class Diagnostic:
-    def __str__(self) -> str: ...
     @property
     def location(self) -> Location: ...
     @property
@@ -1382,7 +1359,6 @@ class DiagnosticHandler:
 
 class DiagnosticInfo:
     def __init__(self, arg0: Diagnostic) -> None: ...
-    def __str__(self) -> str: ...
     @property
     def location(self) -> Location: ...
     @property
@@ -1419,9 +1395,7 @@ class DiagnosticSeverity:
     def __init__(self, value: int) -> None: ...
     def __int__(self) -> int: ...
     def __ne__(self, other: Any) -> bool: ...
-    def __repr__(self) -> str: ...
     def __setstate__(self, state: int) -> None: ...
-    def __str__(self) -> str: ...
     @property
     def name(self) -> str: ...
     @property
@@ -1429,12 +1403,10 @@ class DiagnosticSeverity:
 
 class Dialect:
     def __init__(self, descriptor: DialectDescriptor) -> None: ...
-    def __repr__(self) -> Any: ...
     @property
     def descriptor(self) -> DialectDescriptor: ...
 
 class DialectDescriptor:
-    def __repr__(self) -> str: ...
     @property
     def namespace(self) -> str: ...
 
@@ -1445,8 +1417,8 @@ class DialectRegistry:
     def _CAPIPtr(self) -> object: ...
 
 class Dialects:
-    def __getattr__(self, arg0: str) -> Any: ...
-    def __getitem__(self, arg0: str) -> Any: ...
+    def __getattr__(self, arg0: str) -> Dialect: ...
+    def __getitem__(self, arg0: str) -> Dialect: ...
 
 class DictAttr(Attribute):
     static_typeid: ClassVar[TypeID]  # value = <mlir._mlir_libs._TypeID object>
@@ -1464,7 +1436,6 @@ class DictAttr(Attribute):
     def __getitem__(self, arg0: int) -> NamedAttribute: ...
     def __init__(self, cast_from_attr: Attribute) -> None: ...
     def __len__(self) -> int: ...
-    def __repr__(self) -> str: ...
     @property
     def type(self) -> Type: ...
     @property
@@ -1480,7 +1451,6 @@ class F16Type(Type):
     @staticmethod
     def isinstance(other: Type) -> bool: ...
     def __init__(self, cast_from_type: Type) -> None: ...
-    def __repr__(self) -> str: ...
     @property
     def typeid(self) -> TypeID: ...
 
@@ -1494,7 +1464,6 @@ class F32Type(Type):
     @staticmethod
     def isinstance(other: Type) -> bool: ...
     def __init__(self, cast_from_type: Type) -> None: ...
-    def __repr__(self) -> str: ...
     @property
     def typeid(self) -> TypeID: ...
 
@@ -1508,7 +1477,6 @@ class F64Type(Type):
     @staticmethod
     def isinstance(other: Type) -> bool: ...
     def __init__(self, cast_from_type: Type) -> None: ...
-    def __repr__(self) -> str: ...
     @property
     def typeid(self) -> TypeID: ...
 
@@ -1521,7 +1489,6 @@ class FlatSymbolRefAttr(Attribute):
     @staticmethod
     def isinstance(other: Attribute) -> bool: ...
     def __init__(self, cast_from_attr: Attribute) -> None: ...
-    def __repr__(self) -> str: ...
     @property
     def static_typeid(self) -> TypeID: ...
     @property
@@ -1544,7 +1511,6 @@ class Float8E4M3B11FNUZType(Type):
     @staticmethod
     def isinstance(other: Type) -> bool: ...
     def __init__(self, cast_from_type: Type) -> None: ...
-    def __repr__(self) -> str: ...
     @property
     def typeid(self) -> TypeID: ...
 
@@ -1558,7 +1524,6 @@ class Float8E4M3FNType(Type):
     @staticmethod
     def isinstance(other: Type) -> bool: ...
     def __init__(self, cast_from_type: Type) -> None: ...
-    def __repr__(self) -> str: ...
     @property
     def typeid(self) -> TypeID: ...
 
@@ -1572,7 +1537,6 @@ class Float8E4M3FNUZType(Type):
     @staticmethod
     def isinstance(other: Type) -> bool: ...
     def __init__(self, cast_from_type: Type) -> None: ...
-    def __repr__(self) -> str: ...
     @property
     def typeid(self) -> TypeID: ...
 
@@ -1586,7 +1550,6 @@ class Float8E5M2FNUZType(Type):
     @staticmethod
     def isinstance(other: Type) -> bool: ...
     def __init__(self, cast_from_type: Type) -> None: ...
-    def __repr__(self) -> str: ...
     @property
     def typeid(self) -> TypeID: ...
 
@@ -1600,7 +1563,6 @@ class Float8E5M2Type(Type):
     @staticmethod
     def isinstance(other: Type) -> bool: ...
     def __init__(self, cast_from_type: Type) -> None: ...
-    def __repr__(self) -> str: ...
     @property
     def typeid(self) -> TypeID: ...
 
@@ -1628,7 +1590,6 @@ class FloatAttr(Attribute):
         Converts the value of the float attribute to a Python float
         """
     def __init__(self, cast_from_attr: Attribute) -> None: ...
-    def __repr__(self) -> str: ...
     @property
     def type(self) -> Type: ...
     @property
@@ -1649,7 +1610,6 @@ class FloatTF32Type(Type):
     @staticmethod
     def isinstance(other: Type) -> bool: ...
     def __init__(self, cast_from_type: Type) -> None: ...
-    def __repr__(self) -> str: ...
     @property
     def typeid(self) -> TypeID: ...
 
@@ -1665,7 +1625,6 @@ class FunctionType(Type):
     @staticmethod
     def isinstance(other: Type) -> bool: ...
     def __init__(self, cast_from_type: Type) -> None: ...
-    def __repr__(self) -> str: ...
     @property
     def inputs(self) -> List:
         """
@@ -1689,7 +1648,6 @@ class IndexType(Type):
     @staticmethod
     def isinstance(other: Type) -> bool: ...
     def __init__(self, cast_from_type: Type) -> None: ...
-    def __repr__(self) -> str: ...
     @property
     def typeid(self) -> TypeID: ...
 
@@ -1769,7 +1727,7 @@ class InsertionPoint:
         """
         Inserts before the block terminator.
         """
-    def __enter__(self) -> Any: ...
+    def __enter__(self) -> InsertionPoint: ...
     def __exit__(self, arg0: Any, arg1: Any, arg2: Any) -> None: ...
     @overload
     def __init__(self, block: Block) -> None:
@@ -1810,7 +1768,6 @@ class IntegerAttr(Attribute):
         """
         Converts the value of the integer attribute to a Python int
         """
-    def __repr__(self) -> str: ...
     @property
     def type(self) -> Type: ...
     @property
@@ -1840,8 +1797,6 @@ class IntegerSet:
     @overload
     def __eq__(self, arg0: object) -> bool: ...
     def __hash__(self) -> int: ...
-    def __repr__(self) -> str: ...
-    def __str__(self) -> str: ...
     def dump(self) -> None:
         """
         Dumps a debug representation of the object to stderr.
@@ -1908,7 +1863,6 @@ class IntegerType(Type):
     @staticmethod
     def isinstance(other: Type) -> bool: ...
     def __init__(self, cast_from_type: Type) -> None: ...
-    def __repr__(self) -> str: ...
     @property
     def is_signed(self) -> bool:
         """
@@ -1984,7 +1938,6 @@ class Location:
     @overload
     def __eq__(self, arg0: Location) -> bool: ...
     def __exit__(self, arg0: object, arg1: object, arg2: object) -> None: ...
-    def __repr__(self) -> str: ...
     def emit_error(self, message: str) -> None:
         """
         Emits an error at this location
@@ -2018,7 +1971,6 @@ class MemRefType(ShapedType):
     @staticmethod
     def isinstance(other: Type) -> bool: ...
     def __init__(self, cast_from_type: Type) -> None: ...
-    def __repr__(self) -> str: ...
     @property
     def affine_map(self) -> AffineMap:
         """
@@ -2039,12 +1991,12 @@ class MemRefType(ShapedType):
 
 class Module:
     @staticmethod
-    def create(loc: Optional[Location] = None) -> Any:
+    def create(loc: Optional[Location] = None) -> Module:
         """
         Creates an empty module
         """
     @staticmethod
-    def parse(asm: str, context: Optional[Context] = None) -> Any:
+    def parse(asm: str, context: Optional[Context] = None) -> Module:
         """
         Parses a module's assembly format from a string.
 
@@ -2053,7 +2005,7 @@ class Module:
         See also: https://mlir.llvm.org/docs/LangRef/
         """
     def _CAPICreate(self) -> Any: ...
-    def __str__(self) -> Any:
+    def __str__(self) -> str:
         """
         Gets the assembly form of the operation with default options.
 
@@ -2078,7 +2030,7 @@ class Module:
         Context that created the Module
         """
     @property
-    def operation(self) -> Any:
+    def operation(self) -> Operation:
         """
         Accesses the module as an operation
         """
@@ -2089,7 +2041,6 @@ class MLIRError(Exception):
     ) -> None: ...
 
 class NamedAttribute:
-    def __repr__(self) -> str: ...
     @property
     def attr(self) -> Attribute:
         """
@@ -2111,7 +2062,6 @@ class NoneType(Type):
     @staticmethod
     def isinstance(other: Type) -> bool: ...
     def __init__(self, cast_from_type: Type) -> None: ...
-    def __repr__(self) -> str: ...
     @property
     def typeid(self) -> TypeID: ...
 
@@ -2202,7 +2152,6 @@ class OpView(_OperationBase):
         Parses a specific, generated OpView based on class level attributes
         """
     def __init__(self, operation: _OperationBase) -> None: ...
-    def __str__(self) -> str: ...
     @property
     def operation(self) -> _OperationBase: ...
     @property
@@ -2228,7 +2177,6 @@ class OpaqueAttr(Attribute):
     @staticmethod
     def isinstance(other: Attribute) -> bool: ...
     def __init__(self, cast_from_attr: Attribute) -> None: ...
-    def __repr__(self) -> str: ...
     @property
     def data(self) -> bytes:
         """
@@ -2256,7 +2204,6 @@ class OpaqueType(Type):
     @staticmethod
     def isinstance(other: Type) -> bool: ...
     def __init__(self, cast_from_type: Type) -> None: ...
-    def __repr__(self) -> str: ...
     @property
     def data(self) -> str:
         """
@@ -2305,7 +2252,7 @@ class Operation(_OperationBase):
     @staticmethod
     def parse(
         source: str, *, source_name: str = "", context: Optional[Context] = None
-    ) -> Any:
+    ) -> Operation:
         """
         Parses an operation. Supports both text assembly format and binary bytecode format.
         """
@@ -2327,7 +2274,7 @@ class OperationIterator:
     def __next__(self) -> OpView: ...
 
 class OperationList:
-    def __getitem__(self, arg0: int) -> Any: ...
+    def __getitem__(self, arg0: int) -> OpView: ...
     def __iter__(self) -> OperationIterator: ...
     def __len__(self) -> int: ...
 
@@ -2346,7 +2293,6 @@ class RankedTensorType(ShapedType):
     @staticmethod
     def isinstance(other: Type) -> bool: ...
     def __init__(self, cast_from_type: Type) -> None: ...
-    def __repr__(self) -> str: ...
     @property
     def encoding(self) -> Optional[Attribute]: ...
     @property
@@ -2401,7 +2347,6 @@ class ShapedType(Type):
     @staticmethod
     def isinstance(other: Type) -> bool: ...
     def __init__(self, cast_from_type: Type) -> None: ...
-    def __repr__(self) -> str: ...
     def get_dim_size(self, dim: int) -> int:
         """
         Returns the dim-th dimension of the given ranked shaped type.
@@ -2505,7 +2450,6 @@ class StridedLayoutAttr(Attribute):
     @staticmethod
     def isinstance(other: Attribute) -> bool: ...
     def __init__(self, cast_from_attr: Attribute) -> None: ...
-    def __repr__(self) -> str: ...
     @property
     def offset(self) -> int:
         """
@@ -2536,7 +2480,6 @@ class StringAttr(Attribute):
     @staticmethod
     def isinstance(other: Attribute) -> bool: ...
     def __init__(self, cast_from_attr: Attribute) -> None: ...
-    def __repr__(self) -> str: ...
     @property
     def type(self) -> Type: ...
     @property
@@ -2561,7 +2504,6 @@ class SymbolRefAttr(Attribute):
     @staticmethod
     def isinstance(other: Attribute) -> bool: ...
     def __init__(self, cast_from_attr: Attribute) -> None: ...
-    def __repr__(self) -> str: ...
     @property
     def static_typeid(self) -> TypeID: ...
     @property
@@ -2610,7 +2552,6 @@ class TupleType(Type):
     @staticmethod
     def isinstance(other: Type) -> bool: ...
     def __init__(self, cast_from_type: Type) -> None: ...
-    def __repr__(self) -> str: ...
     def get_type(self, pos: int) -> Type:
         """
         Returns the pos-th type in the Tuple type.
@@ -2633,7 +2574,6 @@ class TypeAttr(Attribute):
     @staticmethod
     def isinstance(other: Attribute) -> bool: ...
     def __init__(self, cast_from_attr: Attribute) -> None: ...
-    def __repr__(self) -> str: ...
     @property
     def type(self) -> Type: ...
     @property
@@ -2661,7 +2601,6 @@ class UnitAttr(Attribute):
     @staticmethod
     def isinstance(other: Attribute) -> bool: ...
     def __init__(self, cast_from_attr: Attribute) -> None: ...
-    def __repr__(self) -> str: ...
     @property
     def type(self) -> Type: ...
     @property
@@ -2679,7 +2618,6 @@ class UnrankedMemRefType(ShapedType):
     @staticmethod
     def isinstance(other: Type) -> bool: ...
     def __init__(self, cast_from_type: Type) -> None: ...
-    def __repr__(self) -> str: ...
     @property
     def memory_space(self) -> Optional[Attribute]:
         """
@@ -2698,7 +2636,6 @@ class UnrankedTensorType(ShapedType):
     @staticmethod
     def isinstance(other: Type) -> bool: ...
     def __init__(self, cast_from_type: Type) -> None: ...
-    def __repr__(self) -> str: ...
     @property
     def typeid(self) -> TypeID: ...
 
@@ -2719,7 +2656,6 @@ class VectorType(ShapedType):
     @staticmethod
     def isinstance(other: Type) -> bool: ...
     def __init__(self, cast_from_type: Type) -> None: ...
-    def __repr__(self) -> str: ...
     @property
     def scalable(self) -> bool: ...
     @property

``````````

</details>


https://github.com/llvm/llvm-project/pull/76728


More information about the Mlir-commits mailing list