nglviewer / nglview

Jupyter widget to interactively view molecular structures and trajectories
http://nglviewer.org/nglview/latest/
Other
788 stars 132 forks source link

`DeprecationWarning` from `traitlets` #1074

Open yuzie007 opened 10 months ago

yuzie007 commented 10 months ago
nglview: 3.0.7
ipywidgets: 8.1.0

First of all, thank you very much @hainm for the development of nglview!

If we use nglview with turning Warning into Exception as

python -W "error" test0.py

where test0.py is

from ase.build import bulk
from nglview.show import show_ase

atoms = bulk("Au")
show_ase(atoms, default=False)

this gives the following error;

Traceback (most recent call last):
  File "/Users/ikeda/miniconda3/envs/myenv/lib/python3.10/site-packages/traitlets/traitlets.py", line 1240, in __init__
    super().__init__(*super_args, **super_kwargs)
TypeError: object.__init__() takes exactly one argument (the instance to initialize)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/ikeda/Documents/projects/nglview/test0.py", line 5, in <module>
    show_ase(atoms, default=False)
  File "/Users/ikeda/miniconda3/envs/myenv/lib/python3.10/site-packages/nglview/show.py", line 85, in show_ase
    return NGLWidget(structure, **kwargs)
  File "/Users/ikeda/miniconda3/envs/myenv/lib/python3.10/site-packages/nglview/widget.py", line 193, in __init__
    super().__init__(**kwargs)
  File "/Users/ikeda/miniconda3/envs/myenv/lib/python3.10/site-packages/ipywidgets/widgets/widget.py", line 503, in __init__
    super().__init__(**kwargs)
  File "/Users/ikeda/miniconda3/envs/myenv/lib/python3.10/site-packages/traitlets/traitlets.py", line 1246, in __init__
    warn(
DeprecationWarning: Passing unrecognized arguments to super(NGLWidget).__init__(default=False).
object.__init__() takes exactly one argument (the instance to initialize)
This is deprecated in traitlets 4.2.This error will be raised in a future release of traitlets.

This is probably not specific for ase but in general for (at least some) show_xxx commands in nglview; the following shows also a similar error

import nglview
nglview.show_pdbid("3pqr", default=False)

I found this issue when I try to solve an issue reported in ase (https://gitlab.com/ase/ase/-/issues/1313). That issue itself is not due to nglview, but when I try to add a test for nglview to solve the issue, the problem I described above emerged. This is because in ase a DeprecationWarning is turned into Exception for safe testing. From the ase side, it would be ideal if this DeprecationWarning issue is solved on the nglview side. It may also make sense, because, as written in the error message above, this issue will raise an error from traitlets in future.

hainm commented 10 months ago

noted. Thanks @yuzie007.