Skip to content

Commit c309642

Browse files
committed
fix pylint.
1 parent 022fa92 commit c309642

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/lightning/pytorch/loggers/utilities.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
# limitations under the License.
1414
"""Utilities for loggers."""
1515

16-
from collections.abc import Mapping
16+
from collections.abc import ItemsView, KeysView, Mapping, ValuesView
1717
from pathlib import Path
18-
from typing import Any, Optional, Self, TypeVar, Union
18+
from typing import Any, Optional, TypeVar, Union
1919

2020
from torch import Tensor
21+
from typing_extensions import Self
2122

2223
import lightning.pytorch as pl
2324
from lightning.pytorch.callbacks import Checkpoint
@@ -120,7 +121,7 @@ def __init__(self, loggers: Union[list[_T], Mapping[str, _T]] = None):
120121
super().__init__(() if loggers is None else loggers)
121122
self._dict: dict = {}
122123

123-
def __eq__(self, other):
124+
def __eq__(self, other: Any) -> bool:
124125
self_list = list(self)
125126
if isinstance(other, _ListMap):
126127
return self_list == list(other) and self._dict == other._dict
@@ -144,7 +145,7 @@ def __iadd__(self, other: Union[list[_T], Self]) -> Self:
144145
# todo
145146
return list.__iadd__(self, other)
146147

147-
def __setitem__(self, key, value):
148+
def __setitem__(self, key: Union[int, slice, str], value: _T) -> None:
148149
if isinstance(key, (int, slice)):
149150
# replace element by index
150151
return list.__setitem__(self, key, value)
@@ -158,14 +159,14 @@ def __setitem__(self, key, value):
158159
return None
159160
raise TypeError("Key must be int or str")
160161

161-
def __contains__(self, item):
162+
def __contains__(self, item: Union[_T, str]) -> bool:
162163
if isinstance(item, str):
163164
return item in self._dict
164165
return list.__contains__(self, item)
165166

166167
# --- Dict-like interface ---
167168

168-
def __delitem__(self, key):
169+
def __delitem__(self, key: Union[int, slice, str]) -> None:
169170
if isinstance(key, (int, slice)):
170171
loggers = list.__getitem__(self, key)
171172
super(list, self).__delitem__(key)
@@ -179,14 +180,14 @@ def __delitem__(self, key):
179180
else:
180181
raise TypeError("Key must be int or str")
181182

182-
def keys(self):
183+
def keys(self) -> KeysView[str]:
183184
return self._dict.keys()
184185

185-
def values(self):
186+
def values(self) -> ValuesView[_T]:
186187
d = {k: self[v] for k, v in self._dict.items()}
187188
return d.values()
188189

189-
def items(self):
190+
def items(self) -> ItemsView[str, _T]:
190191
d = {k: self[v] for k, v in self._dict.items()}
191192
return d.items()
192193

@@ -206,6 +207,6 @@ def pop(self, key: Union[int, str] = -1, default: Optional[Any] = None) -> _T:
206207
return self.pop(self._dict[key])
207208
raise TypeError("Key must be int or str")
208209

209-
def __repr__(self):
210+
def __repr__(self) -> str:
210211
ret = super().__repr__()
211212
return f"_ListMap({ret}, keys={list(self._dict.keys())})"

src/lightning/pytorch/trainer/trainer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ def __init__(
494494
setup._init_profiler(self, profiler)
495495

496496
# init logger flags
497-
self._loggers: list[Logger]
497+
self._loggers: _ListMap[Logger]
498498
self._logger_connector.on_trainer_init(logger, log_every_n_steps)
499499

500500
# init debugging flags

0 commit comments

Comments
 (0)