From b4ec785da67d7f417424519e0a24dda5f99dd83d Mon Sep 17 00:00:00 2001 From: TresYap <33246797+TresYap@users.noreply.github.com> Date: Fri, 20 Dec 2024 01:05:49 +0800 Subject: [PATCH] fix: swapped _R_co and _P to prevent type error. When loading a pytorch-lightning model from MLFlow, I get `TypeError: Type parameter +_R_co without a default follows type parameter with a default`. This happens whenever doing `import pytorch_lightning as pl` which is done by packages like MLFlow. --- src/lightning/pytorch/utilities/model_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lightning/pytorch/utilities/model_helpers.py b/src/lightning/pytorch/utilities/model_helpers.py index 44591aa7f4dc1..daf1c400c03df 100644 --- a/src/lightning/pytorch/utilities/model_helpers.py +++ b/src/lightning/pytorch/utilities/model_helpers.py @@ -104,7 +104,7 @@ def _check_mixed_imports(instance: object) -> None: _R_co = TypeVar("_R_co", covariant=True) # return type of the decorated method -class _restricted_classmethod_impl(Generic[_T, _P, _R_co]): +class _restricted_classmethod_impl(Generic[_T, _R_co, _P]): """Drop-in replacement for @classmethod, but raises an exception when the decorated method is called on an instance instead of a class type."""