Commit cb6a60d
authored
[air] Add stacklevel option to deprecation_warning (#58357)
Currently are deprecation warnings sometimes not informative enough. The
the warning is triggered it does not tell us *where* the deprecated
feature is used. For example, ray internally raises a deprecation
warning when an `RLModuleConfig` is initialized.
```python
>>> from ray.rllib.core.rl_module.rl_module import RLModuleConfig
>>> RLModuleConfig()
2025-11-02 18:21:27,318 WARNING deprecation.py:50 -- DeprecationWarning: `RLModule(config=[RLModuleConfig object])` has been deprecated. Use `RLModule(observation_space=.., action_space=.., inference_only=.., model_config=.., catalog_class=..)` instead. This will raise an error in the future!
```
This is confusing, where did *I* use a config, what am I doing wrong?
This raises issues like:
https://discuss.ray.io/t/warning-deprecation-py-50-deprecationwarning-rlmodule-config-rlmoduleconfig-object-has-been-deprecated-use-rlmodule-observation-space-action-space-inference-only-model-config-catalog-class-instead/23064
Tracing where the error actually happens is tedious - is it my code or
internal? The output just shows `deprecation.:50`. Not helpful.
This PR adds a stacklevel option with stacklevel=2 as the default to all
`deprecation_warning`s. So devs and users can better see where is the
deprecated option actually used.
---
EDIT:
**Before**
```python
WARNING deprecation.py:50 -- DeprecationWarning: `RLModule(config=[RLModuleConfig object])`
```
**After** module.py:line where the deprecated artifact is used is shown
in the log output:
When building an Algorithm:
```python
WARNING rl_module.py:445 -- DeprecationWarning: `RLModule(config=[RLModuleConfig object])` has been deprecated. Use `RLModule(observation_space=.., action_space=.., inference_only=.., model_config=.., catalog_class=..)` instead. This will raise an error in the future!
```
```python
.../ray/tune/logger/unified.py:53: RayDeprecationWarning: This API is deprecated and may be removed in future Ray releases. You could suppress this warning by setting env variable PYTHONWARNINGS="ignore::DeprecationWarning"
```
Signed-off-by: Daraan <[email protected]>1 parent 5bff52a commit cb6a60d
1 file changed
+8
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
33 | 37 | | |
34 | 38 | | |
35 | 39 | | |
| |||
48 | 52 | | |
49 | 53 | | |
50 | 54 | | |
51 | | - | |
| 55 | + | |
| 56 | + | |
52 | 57 | | |
53 | 58 | | |
54 | 59 | | |
| |||
105 | 110 | | |
106 | 111 | | |
107 | 112 | | |
| 113 | + | |
108 | 114 | | |
109 | 115 | | |
110 | 116 | | |
| |||
123 | 129 | | |
124 | 130 | | |
125 | 131 | | |
| 132 | + | |
126 | 133 | | |
127 | 134 | | |
128 | 135 | | |
| |||
0 commit comments