diff --git a/python/taichi/lang/expr.py b/python/taichi/lang/expr.py index 4129786143ad6..05582cd6be9cb 100644 --- a/python/taichi/lang/expr.py +++ b/python/taichi/lang/expr.py @@ -74,7 +74,9 @@ def make_constant_expr(val, dtype): constant_dtype = impl.get_runtime( ).default_ip if dtype is None else dtype if constant_dtype not in integer_types: - raise TaichiTypeError('Integer literals must be annotated with a integer type. For type casting, use `ti.cast`.') + raise TaichiTypeError( + 'Integer literals must be annotated with a integer type. For type casting, use `ti.cast`.' + ) _check_in_range(to_numpy_type(constant_dtype), val) return Expr( _ti_core.make_const_expr_int( @@ -83,7 +85,9 @@ def make_constant_expr(val, dtype): constant_dtype = impl.get_runtime( ).default_fp if dtype is None else dtype if constant_dtype not in real_types: - raise TaichiTypeError('Floating-point literals must be annotated with a floating-point type. For type casting, use `ti.cast`.') + raise TaichiTypeError( + 'Floating-point literals must be annotated with a floating-point type. For type casting, use `ti.cast`.' + ) return Expr(_ti_core.make_const_expr_fp(constant_dtype, val)) raise TaichiTypeError(f'Invalid constant scalar data type: {type(val)}') diff --git a/tests/python/test_literal.py b/tests/python/test_literal.py index bc01753f3bbc9..88ac3827df213 100644 --- a/tests/python/test_literal.py +++ b/tests/python/test_literal.py @@ -62,7 +62,9 @@ def int_annotation_error(): with pytest.raises( ti.TaichiTypeError, - match="Integer literals must be annotated with a integer type. For type casting, use `ti.cast`."): + match= + "Integer literals must be annotated with a integer type. For type casting, use `ti.cast`." + ): int_annotation_error() @@ -74,5 +76,7 @@ def float_annotation_error(): with pytest.raises( ti.TaichiTypeError, - match="Floating-point literals must be annotated with a floating-point type. For type casting, use `ti.cast`."): + match= + "Floating-point literals must be annotated with a floating-point type. For type casting, use `ti.cast`." + ): float_annotation_error()