Skip to content

Commit e63d813

Browse files
authored
Remove the deprecated pytorch_lightning.callbacks.base module (#16319)
1 parent b085fa1 commit e63d813

File tree

5 files changed

+28
-52
lines changed

5 files changed

+28
-52
lines changed

src/pytorch_lightning/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
146146
- Removed the deprecated `pytorch_lightning.core.lightning` module in favor of `pytorch_lightning.core.module` ([#16318](https://github.com/PyTorchLightning/pytorch-lightning/pull/16318))
147147

148148

149+
- Removed the deprecated `pytorch_lightning.callbacks.base` module in favor of `pytorch_lightning.callbacks.callback` ([#16319](https://github.com/PyTorchLightning/pytorch-lightning/pull/16319))
150+
151+
149152
- Removed the deprecated `Trainer.reset_train_val_dataloaders()` in favor of `Trainer.reset_{train,val}_dataloader` ([#16131](https://github.com/Lightning-AI/lightning/pull/16131))
150153

151154

src/pytorch_lightning/_graveyard/callbacks.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,27 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
14+
import sys
1515
from typing import Any
1616

1717
from pytorch_lightning.callbacks import ModelCheckpoint
1818

1919

20+
def _patch_sys_modules() -> None:
21+
# TODO: Remove in v2.0.0
22+
self = sys.modules[__name__]
23+
sys.modules["pytorch_lightning.callbacks.base"] = self
24+
25+
26+
class Callback:
27+
# TODO: Remove in v2.0.0
28+
def __init__(self, *_: Any, **__: Any) -> None:
29+
raise NotImplementedError(
30+
"Importing `pytorch_lightning.callbacks.base.Callback` was deprecated in v1.7.0 and removed as of"
31+
" v1.9.0. Please use `from pytorch_lightning import Callback` instead"
32+
)
33+
34+
2035
def _save_checkpoint(_: ModelCheckpoint, __: Any) -> None:
2136
# TODO: Remove in v2.0.0
2237
raise NotImplementedError(
@@ -25,5 +40,7 @@ def _save_checkpoint(_: ModelCheckpoint, __: Any) -> None:
2540
)
2641

2742

43+
_patch_sys_modules()
44+
2845
# Methods
2946
ModelCheckpoint.save_checkpoint = _save_checkpoint

src/pytorch_lightning/callbacks/base.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

tests/tests_pytorch/deprecated_api/test_remove_1-9.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

tests/tests_pytorch/graveyard/test_callbacks.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717
from pytorch_lightning.callbacks import ModelCheckpoint
1818

1919

20+
def test_v2_0_0_moved_callback():
21+
from pytorch_lightning.callbacks.base import Callback
22+
23+
with pytest.raises(NotImplementedError, match="base.Callback.*was deprecated in v1.7.0 and removed as of v1.9"):
24+
Callback()
25+
26+
2027
def test_v2_0_0_deprecated_mc_save_checkpoint():
2128
mc = ModelCheckpoint()
2229
with pytest.raises(

0 commit comments

Comments
 (0)