From 7cab180f1b6994e6e2187cd40f1feda0e07557bd Mon Sep 17 00:00:00 2001 From: Lin Jiang Date: Fri, 28 Oct 2022 20:59:47 +0800 Subject: [PATCH] [Bug] [error] Add argument 'module' to 'warn_explicit' to show the deprecated warning (#6467) Issue: fixes #6423 ### Brief Summary Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- python/taichi/lang/ast/ast_transformer.py | 27 ++++++++++++++++------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/python/taichi/lang/ast/ast_transformer.py b/python/taichi/lang/ast/ast_transformer.py index c28b66b04a363..d53ad8b0929ea 100644 --- a/python/taichi/lang/ast/ast_transformer.py +++ b/python/taichi/lang/ast/ast_transformer.py @@ -426,8 +426,11 @@ def build_call_if_is_builtin(ctx, node, args, keywords): name = "min" if func is min else "max" warnings.warn_explicit( f'Calling builtin function "{name}" in Taichi scope is deprecated. ' - f'Please use "ti.{name}" instead.', DeprecationWarning, - ctx.file, node.lineno + ctx.lineno_offset) + f'Please use "ti.{name}" instead.', + DeprecationWarning, + ctx.file, + node.lineno + ctx.lineno_offset, + module="taichi") return True return False @@ -471,8 +474,11 @@ def warn_if_is_external_func(ctx, node): f'Calling non-taichi function "{name}". ' f'Scope inside the function is not processed by the Taichi AST transformer. ' f'The function may not work as expected. Proceed with caution! ' - f'Maybe you can consider turning it into a @ti.func?', UserWarning, - ctx.file, node.lineno + ctx.lineno_offset) + f'Maybe you can consider turning it into a @ti.func?', + UserWarning, + ctx.file, + node.lineno + ctx.lineno_offset, + module="taichi") @staticmethod def build_Call(ctx, node): @@ -902,8 +908,10 @@ def build_Compare(ctx, node): name = "is" if isinstance(node_op, ast.Is) else "is not" warnings.warn_explicit( f'Operator "{name}" in Taichi scope is deprecated. Please avoid using it.', - DeprecationWarning, ctx.file, - node.lineno + ctx.lineno_offset) + DeprecationWarning, + ctx.file, + node.lineno + ctx.lineno_offset, + module="taichi") if op is None: if type(node_op) in ops_static: raise TaichiSyntaxError( @@ -1324,8 +1332,11 @@ def build_IfExp(ctx, node): warnings.warn_explicit( 'Using conditional expression for element-wise select operation on ' 'Taichi vectors/matrices is deprecated. ' - 'Please use "ti.select" instead.', DeprecationWarning, - ctx.file, node.lineno + ctx.lineno_offset) + 'Please use "ti.select" instead.', + DeprecationWarning, + ctx.file, + node.lineno + ctx.lineno_offset, + module="taichi") return node.ptr is_static_if = (ASTTransformer.get_decorator(ctx,