Fix mypy errors attributed to `pytorch_lightning.loggers.base.py` (#13494)
Co-authored-by: Rohit Gupta <rohitgr1998@gmail.com> Co-authored-by: Carlos Mocholí <carlossmocholi@gmail.com>
This commit is contained in:
parent
0a6dc5239a
commit
57f5e18587
|
@ -59,7 +59,6 @@ module = [
|
|||
"pytorch_lightning.demos.boring_classes",
|
||||
"pytorch_lightning.demos.mnist_datamodule",
|
||||
"pytorch_lightning.distributed.dist",
|
||||
"pytorch_lightning.loggers.base",
|
||||
"pytorch_lightning.loggers.comet",
|
||||
"pytorch_lightning.loggers.mlflow",
|
||||
"pytorch_lightning.loggers.neptune",
|
||||
|
|
|
@ -12,16 +12,20 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from typing import Callable, Dict, Mapping, Optional, Sequence
|
||||
|
||||
import numpy as np
|
||||
|
||||
import pytorch_lightning.loggers.logger as logger
|
||||
from pytorch_lightning.utilities.warnings import rank_zero_deprecation
|
||||
|
||||
|
||||
def rank_zero_experiment(*args, **kwargs) -> None: # type: ignore[no-untyped-def]
|
||||
def rank_zero_experiment(fn: Callable) -> Callable:
|
||||
rank_zero_deprecation(
|
||||
"The `pytorch_lightning.loggers.base.rank_zero_experiment` is deprecated in v1.7"
|
||||
" and will be removed in v1.9. Please use `pytorch_lightning.loggers.logger.rank_zero_experiment` instead."
|
||||
)
|
||||
return logger.rank_zero_experiment(*args, **kwargs)
|
||||
return logger.rank_zero_experiment(fn)
|
||||
|
||||
|
||||
class LightningLoggerBase(logger.Logger):
|
||||
|
@ -77,9 +81,13 @@ class DummyLogger(logger.DummyLogger):
|
|||
super().__init__(*args, **kwargs)
|
||||
|
||||
|
||||
def merge_dicts(*args, **kwargs) -> None: # type: ignore[no-untyped-def]
|
||||
def merge_dicts(
|
||||
dicts: Sequence[Mapping],
|
||||
agg_key_funcs: Optional[Mapping] = None,
|
||||
default_func: Callable[[Sequence[float]], float] = np.mean,
|
||||
) -> Dict:
|
||||
rank_zero_deprecation(
|
||||
"The `pytorch_lightning.loggers.base.merge_dicts` is deprecated in v1.7"
|
||||
" and will be removed in v1.9. Please use `pytorch_lightning.loggers.logger.merge_dicts` instead."
|
||||
)
|
||||
return logger.merge_dicts(*args, **kwargs)
|
||||
return logger.merge_dicts(dicts=dicts, agg_key_funcs=agg_key_funcs, default_func=default_func)
|
||||
|
|
|
@ -38,13 +38,13 @@ def rank_zero_experiment(fn: Callable) -> Callable:
|
|||
def experiment(self) -> Union[Any, DummyExperiment]: # type: ignore[no-untyped-def]
|
||||
"""
|
||||
Note:
|
||||
`self` is a custom logger instance. The loggers typical wrap an `experiment` method
|
||||
with a @rank_zero_experiment decorator. An exception being `loggers.neptune` wraps
|
||||
`experiment` and `run` with rank_zero_experiment.
|
||||
``self`` is a custom logger instance. The loggers typically wrap an ``experiment`` method
|
||||
with a ``@rank_zero_experiment`` decorator. An exception is that ``loggers.neptune`` wraps
|
||||
``experiment`` and ``run`` with rank_zero_experiment.
|
||||
|
||||
Union[Any, DummyExperiment] is used because the wrapped hooks have several returns
|
||||
types that are specific to the custom logger. The return type can be considered as
|
||||
Union[return type of logger.experiment, DummyExperiment]
|
||||
``Union[Any, DummyExperiment]`` is used because the wrapped hooks have several return
|
||||
types that are specific to the custom logger. The return type here can be considered as
|
||||
``Union[return type of logger.experiment, DummyExperiment]``.
|
||||
"""
|
||||
|
||||
@rank_zero_only
|
||||
|
|
Loading…
Reference in New Issue