metaopt / optree

OpTree: Optimized PyTree Utilities
https://optree.readthedocs.io
Apache License 2.0
136 stars 6 forks source link

[BUG] Importing OpTree 0.12.0 raises `FutureWarning`s (regression) #148

Closed JulianJvn closed 2 months ago

JulianJvn commented 2 months ago

Required prerequisites

What version of OpTree are you using?

0.12.0

System information

OpTree was installed via pip install optree==0.12.0.

>>> import sys, optree
>>> print(sys.version, sys.platform)
3.12.4 (tags/v3.12.4:8e8a4ba, Jun  6 2024, 19:30:16) [MSC v.1940 64 bit (AMD64)] win32
>>> print(optree.__version__)
0.12.0

Problem description

Just running import optree raises FutureWarnings since 0.12.0, which breaks our tests. Warnings are suppressed in default Python REPLs, so you have to run Python with python -W default or python -W error to see it.

The warning happens with OpTree 0.12.0, it doesn't happen with 0.11.0.

Since OpTree is a dependency of Keras, I could imagine this affects others as well.

Reproducible example code

python -W error -c 'import optree'

or (without tracebacks)

import warnings
warnings.simplefilter("default")
import optree

Traceback

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File ".venv\Lib\site-packages\optree\__init__.py", line 17, in <module>
    from optree import accessor, functools, integration, typing
  File ".venv\Lib\site-packages\optree\functools.py", line 24, in <module>
    from optree import registry
  File ".venv\Lib\site-packages\optree\registry.py", line 738, in <module>
    class GetitemKeyPathEntry(KeyPathEntry):
  File ".venv\Lib\site-packages\typing_extensions.py", line 2839, in __init_subclass__
    warnings.warn(msg, category=category, stacklevel=stacklevel + 1)
FutureWarning: The key path API is deprecated and will be removed in a future version. Please use the accessor API instead.

Expected behavior

No warnings are raised when importing OpTree.

Additional context

No response

XuehaiPan commented 2 months ago

Thanks for raising this. I will release a patch release to resolve this.