fix: show the save_to_* deprecation to users, attributed to their code - #1346
davidberenstein1957 wants to merge 3 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1346 +/- ##
==========================================
+ Coverage 91.70% 91.72% +0.02%
==========================================
Files 49 49
Lines 5157 5183 +26
==========================================
+ Hits 4729 4754 +25
- Misses 428 429 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
3958b57 to
b5cf269
Compare
The warning is raised inside _resolve_output_methods, so it is attributed to emissions_tracker.py and Python's default filter -- which only shows DeprecationWarning from __main__ -- drops it for every user. FutureWarning exists for exactly this: deprecations aimed at end users that must always be shown. It makes stacklevel irrelevant to visibility. (skip_file_prefixes= would be the stdlib answer, but it is 3.12+ and requires-python is >=3.10.) Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
b5cf269 to
55855fb
Compare
Verdict: 🔧 Request changesThe title and description mention a dynamic stacklevel and moving the CLI to Must fix:
Switching to |
…tput_methods Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
Made the changes in 99b6c55: CLI moved to |
Resolve conflict in codecarbon/cli/monitor.py: keep master's conditional log_level forwarding via tracker_args and the PR's removal of the deprecated save_to_logger argument. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
Merged master to resolve conflicts in db90765. |
Description
The
save_to_*deprecation is now aFutureWarning(shown by default per PEP 565), and itsstacklevelis computed by a new_caller_stacklevel()helper, which walks the stack to the first frame outside thecodecarbonpackage (skipping thecontextlibframe added by@suppress). The warning now points at the user'sEmissionsTracker(...)/OfflineEmissionsTracker(...)line instead ofemissions_tracker.py. Incodecarbon/cli/main.py,monitornow passesoutput_methods=built from configuration, withOutputMethod.APIadded for--apiand removed for--no-api, preservingsave_to_api=api's add/remove behaviour and making--apiwork even whenoutput_methodsis set in the config;detectpassesoutput_methods=[].codecarbon/cli/monitor.pydrops thesave_to_logger=Falseargument, which was the default anyway.Related Issue
Fixes #1323
Motivation and Context
The deprecation warning was raised inside
_resolve_output_methods, so it was attributed toemissions_tracker.py, and Python's default filter only showsDeprecationWarningfrom__main__, which dropped the warning for every user.FutureWarningis the correct category for deprecations aimed at end users that must always be shown, and it also makesstacklevelaccuracy matter for pointing at the right line.How Has This Been Tested?
test_deprecation_warning_survives_the_default_filternow also assertsw.filename == __file__for both tracker classes.output_methodsinstead ofsave_to_api; a new parametrisedtest_monitor_api_flag_adds_to_configured_output_methodspins the add/remove behaviour against configured outputs.Screenshots (if appropriate):
N/A
Types of changes
AI Usage Disclosure
Checklist: