Skip to content

assert with more information to help debug #132194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

fengxie
Copy link
Contributor

@fengxie fengxie commented Mar 20, 2025

This PR output debug message to assertion to help debug user python code. Will print out more friendly information

>           assert isinstance(arg, _cext.ir.Value), f"expects Value, got {type(arg)}"                                                          
E           AssertionError: expected Value, got <class 'UserDefinedClass'>       

@llvmbot
Copy link
Member

llvmbot commented Mar 20, 2025

@llvm/pr-subscribers-mlir

Author: drazi (fengxie)

Changes

This PR output debug message to assertion to help debug user python code. Will print out more friendly information

&gt;           assert isinstance(arg, _cext.ir.Value), f"expects Value, got {type(arg)}"                                                          
E           AssertionError: expected Value, got &lt;class 'UserDefinedClass'&gt;       

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

1 Files Affected:

  • (modified) mlir/python/mlir/dialects/_ods_common.py (+3-4)
diff --git a/mlir/python/mlir/dialects/_ods_common.py b/mlir/python/mlir/dialects/_ods_common.py
index 1e7e8244ed442..11c363abe2ecd 100644
--- a/mlir/python/mlir/dialects/_ods_common.py
+++ b/mlir/python/mlir/dialects/_ods_common.py
@@ -104,7 +104,7 @@ def get_op_result_or_value(
     elif isinstance(arg, _cext.ir.OpResultList):
         return arg[0]
     else:
-        assert isinstance(arg, _cext.ir.Value)
+        assert isinstance(arg, _cext.ir.Value), f"expects Value, got {type(arg)}"
         return arg
 
 
@@ -137,11 +137,10 @@ def get_op_result_or_op_results(
     return (
         list(get_op_results_or_values(op))
         if len(op.results) > 1
-        else get_op_result_or_value(op)
-        if len(op.results) > 0
-        else op
+        else get_op_result_or_value(op) if len(op.results) > 0 else op
     )
 
+
 ResultValueTypeTuple = _cext.ir.Operation, _cext.ir.OpView, _cext.ir.Value
 ResultValueT = _Union[ResultValueTypeTuple]
 VariadicResultValueT = _Union[ResultValueT, _Sequence[ResultValueT]]

@@ -147,6 +147,7 @@ def get_op_result_or_op_results(
else:
return op


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spurious change here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suspect introduced by auto formatter :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mlir:python MLIR Python bindings mlir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants