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

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]]

@fengxie
Copy link
Contributor Author

fengxie commented May 28, 2025

Do we need more input to approve this PR? It's a small change.

@makslevental
Copy link
Contributor

Do we need more input to approve this PR? It's a small change.

It's approved - you're saying you would like to merge it?

@fengxie
Copy link
Contributor Author

fengxie commented May 29, 2025

It's approved - you're saying you would like to merge it?

Yes, I would like to merge it.

@makslevental makslevental merged commit 25c5235 into llvm:main May 29, 2025
11 checks passed
svkeerthy pushed a commit that referenced this pull request May 29, 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'>       
```
google-yfyang pushed a commit to google-yfyang/llvm-project that referenced this pull request May 29, 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'>       
```
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Jun 3, 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'>       
```
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.

4 participants