Skip to content

Commit 79f4711

Browse files
committed
Fixed issue with name attribute in CallableEventWithFilter
Fixes #2904 - Replaced DynamicClassAttribute by property - other minor updates
1 parent fb70c09 commit 79f4711

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

ignite/engine/events.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import weakref
44
from collections.abc import Sequence
55
from enum import Enum
6-
from types import DynamicClassAttribute
76
from typing import Any, Callable, Dict, Iterable, Iterator, List, Optional, TYPE_CHECKING, Union
87

98
from torch.utils.data import DataLoader
@@ -34,16 +33,15 @@ def __init__(self, value: str, event_filter: Optional[Callable] = None, name: Op
3433
if not hasattr(self, "_value_"):
3534
self._value_ = value
3635

37-
if not hasattr(self, "_name_") and name is not None:
36+
if not hasattr(self, "_name_"):
3837
self._name_ = name
3938

40-
# copied to be compatible to enum
41-
@DynamicClassAttribute
39+
@property
4240
def name(self) -> str:
4341
"""The name of the Enum member."""
4442
return self._name_
4543

46-
@DynamicClassAttribute
44+
@property
4745
def value(self) -> str:
4846
"""The value of the Enum member."""
4947
return self._value_
@@ -197,15 +195,15 @@ def __eq__(self, other: Any) -> bool:
197195
return NotImplemented
198196

199197
def __hash__(self) -> int:
200-
return hash(self._name_)
198+
return hash(self.name)
201199

202200
def __or__(self, other: Any) -> "EventsList":
203201
return EventsList() | self | other
204202

205203

206204
class EventEnum(CallableEventWithFilter, Enum):
207-
"""Base class for all :class:`~ignite.engine.events.Events`. User defined custom events should also inherit
208-
this class.
205+
"""Base class for all :class:`~ignite.engine.events.Events`. User defined custom events should inherit
206+
from this class.
209207
210208
Examples:
211209
Custom events based on the loss calculation and backward pass can be created as follows:

0 commit comments

Comments
 (0)