From 05e152cc9f9899e3111fb88b395d72e775eec879 Mon Sep 17 00:00:00 2001 From: Lin Jiang Date: Fri, 20 Jan 2023 15:59:39 +0800 Subject: [PATCH] [Error] Remove deprecations in taichi/__init__.py in v1.6.0 (#7222) Issue: #7189 ### Brief Summary --- python/taichi/__init__.py | 45 ++++++++++++++------------------ tests/python/test_deprecation.py | 9 +++++++ 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/python/taichi/__init__.py b/python/taichi/__init__.py index e96ae156999cc..63cb94afeb65a 100644 --- a/python/taichi/__init__.py +++ b/python/taichi/__init__.py @@ -59,33 +59,26 @@ 'lang.mesh._TetMesh') } -if sys.version_info.minor < 7: - for name, alter in __deprecated_names__.items(): - exec(f'{name} = {alter}') - for _origin, (_msg, _replace) in __customized_deprecations__.items(): - exec(f'{_origin} = {_replace}') -else: - def __getattr__(attr): - # There's no easy way to hook accessing attribute with function calls in python3.6. - # So let's skip it for now. - import warnings # pylint: disable=C0415,W0621 - if attr == 'cfg': - return None if lang.impl.get_runtime( - ).prog is None else lang.impl.current_cfg() - if attr in __deprecated_names__: - warnings.warn( - f'ti.{attr} is deprecated. Please use ti.{__deprecated_names__[attr]} instead.', - DeprecationWarning) - exec(f'{attr} = {__deprecated_names__[attr]}') - return locals()[attr] - if attr in __customized_deprecations__: - msg, fun = __customized_deprecations__[attr] - warnings.warn(f'ti.{attr} is deprecated. {msg}', - DeprecationWarning) - exec(f'{attr} = {fun}') - return locals()[attr] - raise AttributeError(f"module '{__name__}' has no attribute '{attr}'") +def __getattr__(attr): + import warnings # pylint: disable=C0415,W0621 + if attr == 'cfg': + return None if lang.impl.get_runtime( + ).prog is None else lang.impl.current_cfg() + if attr in __deprecated_names__: + warnings.warn( + f'ti.{attr} is deprecated, and it will be removed in Taichi v1.6.0. Please use ti.{__deprecated_names__[attr]} instead.', + DeprecationWarning) + exec(f'{attr} = {__deprecated_names__[attr]}') + return locals()[attr] + if attr in __customized_deprecations__: + msg, fun = __customized_deprecations__[attr] + warnings.warn( + f'ti.{attr} is deprecated, and it will be removed in Taichi v1.6.0. {msg}', + DeprecationWarning) + exec(f'{attr} = {fun}') + return locals()[attr] + raise AttributeError(f"module '{__name__}' has no attribute '{attr}'") __version__ = (_ti_core.get_version_major(), _ti_core.get_version_minor(), diff --git a/tests/python/test_deprecation.py b/tests/python/test_deprecation.py index d63bf9d02e5a9..6f1cf3c8632e7 100644 --- a/tests/python/test_deprecation.py +++ b/tests/python/test_deprecation.py @@ -135,3 +135,12 @@ def ker(tex: ti.types.rw_texture(num_dimensions=2, lod=0)): for i, j in ti.ndrange(n, n): ret = ti.cast(1, ti.f32) tex.store(ti.Vector([i, j]), ti.Vector([ret, 0.0, 0.0, 0.0])) + + +@test_utils.test() +def test_deprecation_in_taichi_init_py(): + with pytest.warns( + DeprecationWarning, + match= + "ti.SOA is deprecated, and it will be removed in Taichi v1.6.0."): + ti.SOA