Skip to content

Add typing for utilities/enums.py #11298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ module = [
"pytorch_lightning.trainer.callback_hook",
"pytorch_lightning.trainer.connectors.accelerator_connector",
"pytorch_lightning.trainer.connectors.callback_connector",
"pytorch_lightning.trainer.connectors.checkpoint_connector",
"pytorch_lightning.trainer.connectors.data_connector",
"pytorch_lightning.trainer.data_loading",
"pytorch_lightning.trainer.optimizers",
Expand All @@ -102,7 +101,6 @@ module = [
"pytorch_lightning.utilities.data",
"pytorch_lightning.utilities.deepspeed",
"pytorch_lightning.utilities.distributed",
"pytorch_lightning.utilities.enums",
"pytorch_lightning.utilities.fetching",
"pytorch_lightning.utilities.memory",
"pytorch_lightning.utilities.meta",
Expand Down
13 changes: 8 additions & 5 deletions pytorch_lightning/utilities/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ def from_str(cls, value: str) -> Optional["LightningEnum"]:
return getattr(cls, st)
return None

def __eq__(self, other: Union[str, Enum]) -> bool:
other = other.value if isinstance(other, Enum) else str(other)
def __eq__(self, other: object) -> bool:
if isinstance(other, Enum):
other = other.value
elif not isinstance(other, str):
return NotImplemented
return self.value.lower() == other.lower()

def __hash__(self) -> int:
Expand All @@ -55,12 +58,12 @@ def __getattribute__(cls, name: str) -> Any:
return obj

def __getitem__(cls, name: str) -> Any:
member = super().__getitem__(name)
member: _OnAccessEnumMeta = super().__getitem__(name)
member.deprecate()
return member

def __call__(cls, value: str, *args: Any, **kwargs: Any) -> Any:
obj = super().__call__(value, *args, **kwargs)
def __call__(cls, *args: Any, **kwargs: Any) -> Any:
obj = super().__call__(*args, **kwargs)
if isinstance(obj, Enum):
obj.deprecate()
return obj
Expand Down