Skip to content

Commit 1bef5c8

Browse files
authored
Remove the deprecated pytorch_lightning.core.lightning module (#16318)
1 parent 0459da7 commit 1bef5c8

File tree

5 files changed

+30
-37
lines changed

5 files changed

+30
-37
lines changed

src/pytorch_lightning/CHANGELOG.md

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

145145

146+
- Removed the deprecated `pytorch_lightning.core.lightning` module in favor of `pytorch_lightning.core.module` ([#16318](https://github.com/PyTorchLightning/pytorch-lightning/pull/16318))
147+
148+
146149
- 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))
147150

148151

src/pytorch_lightning/_graveyard/core.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +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+
import sys
1415
from typing import Any
1516

1617
from pytorch_lightning import LightningDataModule
1718

1819

20+
def _patch_sys_modules() -> None:
21+
# TODO: Remove in v2.0.0
22+
self = sys.modules[__name__]
23+
sys.modules["pytorch_lightning.core.lightning"] = self
24+
25+
26+
class LightningModule:
27+
# TODO: Remove in v2.0.0
28+
def __init__(self, *_: Any, **__: Any) -> None:
29+
raise NotImplementedError(
30+
"Importing `pytorch_lightning.core.lightning.LightningModule` was deprecated in v1.7.0 and removed as of"
31+
" v1.9.0. Please use `from pytorch_lightning import LightningModule` instead"
32+
)
33+
34+
1935
def _on_save_checkpoint(_: LightningDataModule, __: Any) -> None:
2036
# TODO: Remove in v2.0.0
2137
raise NotImplementedError(
@@ -32,6 +48,8 @@ def _on_load_checkpoint(_: LightningDataModule, __: Any) -> None:
3248
)
3349

3450

51+
_patch_sys_modules()
52+
3553
# Methods
3654
LightningDataModule.on_save_checkpoint = _on_save_checkpoint
3755
LightningDataModule.on_load_checkpoint = _on_load_checkpoint

src/pytorch_lightning/core/lightning.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 & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,6 @@
1515
import pytest
1616

1717

18-
def test_old_lightningmodule_path():
19-
from pytorch_lightning.core.lightning import LightningModule
20-
21-
with pytest.deprecated_call(
22-
match="pytorch_lightning.core.lightning.LightningModule has been deprecated in v1.7"
23-
" and will be removed in v1.9."
24-
):
25-
LightningModule()
26-
27-
2818
def test_old_callback_path():
2919
from pytorch_lightning.callbacks.base import Callback
3020

tests/tests_pytorch/graveyard/test_core.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@
1717
from pytorch_lightning.demos.boring_classes import BoringDataModule, BoringModel
1818

1919

20+
def test_v2_0_0_moved_lightningmodule():
21+
from pytorch_lightning.core.lightning import LightningModule
22+
23+
with pytest.raises(
24+
NotImplementedError, match="lightning.LightningModule.*was deprecated in v1.7.0 and removed as of v1.9"
25+
):
26+
LightningModule()
27+
28+
2029
def test_v2_0_0_unsupported_datamodule_on_save_load_checkpoint():
2130
datamodule = LightningDataModule()
2231
with pytest.raises(

0 commit comments

Comments
 (0)