Skip to content

Commit

Permalink
[Error] Remove deprecations in taichi/__init__.py in v1.6.0 (#7222)
Browse files Browse the repository at this point in the history
Issue: #7189

### Brief Summary
  • Loading branch information
lin-hitonami authored Jan 20, 2023
1 parent 8726253 commit 05e152c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
45 changes: 19 additions & 26 deletions python/taichi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
9 changes: 9 additions & 0 deletions tests/python/test_deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 05e152c

Please sign in to comment.