Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maint: deprecation warning for traitlets #3234

Closed
mattijn opened this issue Oct 20, 2023 · 6 comments · Fixed by #3557
Closed

maint: deprecation warning for traitlets #3234

mattijn opened this issue Oct 20, 2023 · 6 comments · Fixed by #3557
Assignees

Comments

@mattijn
Copy link
Contributor

mattijn commented Oct 20, 2023

In the Github Actions is appearing the following warning message:

=============================== warnings summary ===============================
tests/test_jupyter_chart.py: 30 warnings
  /opt/hostedtoolcache/Python/3.11.6/x64/lib/python3.11/site-packages/traitlets/traitlets.py:869: 
  DeprecationWarning: Deprecated in traitlets 4.1, use the instance .metadata dictionary directly, 
  like x.metadata[key] or x.metadata.get(key, default)

We use traitlets within the altair.JupyterChart() class, I did a quick scan of jupyter_chart.py in comparison with traitlets migration docs for 4.1, but I cannot see something that require changing. Not sure where this warning is coming from. You have any idea @jonmmease?

@jonmmease
Copy link
Contributor

Huh, I'm not sure what's triggering that. From the traitlets code, it looks like the deprecation warning is raised when calling the instance.get_metadata() method: https://github.com/ipython/traitlets/blob/fc130b2d44338c8716bab5d409ce7487674f4d15/traitlets/traitlets.py#L860

But we're not doing this directly. I'll try to step through with a debugger to see where this is happening.

@jonmmease jonmmease self-assigned this Oct 20, 2023
@flekschas
Copy link

@jonmmease did you ever find out what's triggering these warnings? I'm seeing them in one of my projects too and we're also not using get_metadata().

@jonmmease
Copy link
Contributor

No, I don't think I followed through on digging into it

@dangotbanned
Copy link
Member

dangotbanned commented Aug 4, 2024

I'm pretty sure I added filters to the tests that produce this (to ignore) but had no idea this issue existed

If this is the same thing, I couldn't find the source either.

I'll have a look tomorrow and report back

@dangotbanned
Copy link
Member

dangotbanned commented Aug 5, 2024

@flekschas @jonmmease

Hopefully these help:

If you can find where the Warning is emitted, try changing stacklevel=2 -> stacklevel=3 or higher (directly in the traitlets code) to debug.

See warnings.warn for more info on stacklevel.


Update

So far it seems to be triggered by any attribute access of an altair.jupyter_chart.(Selections|Params) instance.

Changing stacklevel=2 -> stacklevel=3 here led me to ipywidgets.Widget.add_traits(), which does call trait.get_metadata('sync').

mro leads to Widget

  • altair.JupyterChart
  • anywidget.AnyWidget
  • ipywidgets.DOMWidget
  • ipywidgets.Widget

@dangotbanned
Copy link
Member

dangotbanned commented Aug 5, 2024

@mattijn you could consider this fixed, if all you wanted was to avoid the warning in GitHub Actions/pytest.
I imagine you might have wanted to fix the source though.

Unless what I suggested in #3234 (comment) is able to identify the trigger, we're a bit stuck due to how the warning was written in traitlets.

Update

This PR uses the exact fix I came up with, but is failing the ipywidgets CI.
It doesn't break the altair test suite and removes the warnings

Update 2

Linking this PR, as it is likely the other PR won't be merged before that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants