Skip to content

Fix: Don't modify global warnings.formatwarning#5482

Open
RamiNoodle733 wants to merge 1 commit intoplotly:mainfrom
RamiNoodle733:fix-warnings-format-5472
Open

Fix: Don't modify global warnings.formatwarning#5482
RamiNoodle733 wants to merge 1 commit intoplotly:mainfrom
RamiNoodle733:fix-warnings-format-5472

Conversation

@RamiNoodle733
Copy link

This PR fixes issue #5472.

Problem

The codebase was modifying the global warnings.formatwarning function in two places:

  • packages/python/plotly/plotly/io/_renderers/renderer.py
  • packages/python/plotly/plotly/io/_renderers/tools.py

Modifying global warning state is bad practice as it can affect user code and other libraries in unexpected ways.

Solution

This PR removes the global warnings.formatwarning modification from both files. Users who want custom warning formatting can do so in their own code without plotly interfering with global state.

Fixes #5472

Remove global modification of warnings.formatwarning from:
- plotly/tools.py
- plotly/matplotlylib/renderer.py

The previous implementation was setting warnings.formatwarning to a custom
function at module import time, which changed the warning format for all
warnings in the Python process, not just plotly's warnings.

This fix ensures plotly doesn't interfere with Python's default warning
format or any custom format set by the user.

Added test to verify warnings.formatwarning is not modified by plotly imports.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: plotly breaks warnings format

1 participant