mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-04-24 15:27:17 +00:00
style: highligh __del__ methods in formatting
This commit is contained in:
parent
e03fcbfab5
commit
d77cf7c4bb
@ -122,7 +122,7 @@ Again, the most checks can be performed by `make check` command, though some add
|
|||||||
def __hash__(self) -> int: ... # basically any magic (or look-alike) method
|
def __hash__(self) -> int: ... # basically any magic (or look-alike) method
|
||||||
```
|
```
|
||||||
|
|
||||||
Methods inside one group should be ordered alphabetically, the only exceptions are `__init__` (`__post_init__` for dataclasses) and `__new__` methods which should be defined first. For test methods it is recommended to follow the order in which functions are defined.
|
Methods inside one group should be ordered alphabetically, the only exceptions are `__init__` (`__post_init__` for dataclasses), `__new__` and `__del__` methods which should be defined first. For test methods it is recommended to follow the order in which functions are defined.
|
||||||
|
|
||||||
Though, we would like to highlight abstract methods (i.e. ones which raise `NotImplementedError`), we still keep in global order at the moment.
|
Though, we would like to highlight abstract methods (i.e. ones which raise `NotImplementedError`), we still keep in global order at the moment.
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ class MethodTypeOrder(StrEnum):
|
|||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
Class(MethodTypeOrder): (class attribute) class method
|
Class(MethodTypeOrder): (class attribute) class method
|
||||||
|
Delete(MethodTypeOrder): (class attribute) destructor-like methods
|
||||||
Init(MethodTypeOrder): (class attribute) initialization method
|
Init(MethodTypeOrder): (class attribute) initialization method
|
||||||
Magic(MethodTypeOrder): (class attribute) other magical methods
|
Magic(MethodTypeOrder): (class attribute) other magical methods
|
||||||
New(MethodTypeOrder): (class attribute) constructor method
|
New(MethodTypeOrder): (class attribute) constructor method
|
||||||
@ -40,6 +41,7 @@ class MethodTypeOrder(StrEnum):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
Class = "classmethod"
|
Class = "classmethod"
|
||||||
|
Delete = "del"
|
||||||
Init = "init"
|
Init = "init"
|
||||||
Magic = "magic"
|
Magic = "magic"
|
||||||
New = "new"
|
New = "new"
|
||||||
@ -76,8 +78,9 @@ class DefinitionOrder(BaseRawFileChecker):
|
|||||||
"method-type-order",
|
"method-type-order",
|
||||||
{
|
{
|
||||||
"default": [
|
"default": [
|
||||||
"new",
|
|
||||||
"init",
|
"init",
|
||||||
|
"new",
|
||||||
|
"del",
|
||||||
"property",
|
"property",
|
||||||
"classmethod",
|
"classmethod",
|
||||||
"staticmethod",
|
"staticmethod",
|
||||||
@ -122,10 +125,12 @@ class DefinitionOrder(BaseRawFileChecker):
|
|||||||
MethodTypeOrder: resolved function type
|
MethodTypeOrder: resolved function type
|
||||||
"""
|
"""
|
||||||
# init methods
|
# init methods
|
||||||
if function.name in ("__new__",):
|
|
||||||
return MethodTypeOrder.New
|
|
||||||
if function.name in ("__init__", "__post_init__"):
|
if function.name in ("__init__", "__post_init__"):
|
||||||
return MethodTypeOrder.Init
|
return MethodTypeOrder.Init
|
||||||
|
if function.name in ("__new__",):
|
||||||
|
return MethodTypeOrder.New
|
||||||
|
if function.name in ("__del__",):
|
||||||
|
return MethodTypeOrder.Delete
|
||||||
|
|
||||||
# decorated methods
|
# decorated methods
|
||||||
decorators = []
|
decorators = []
|
||||||
|
@ -65,6 +65,14 @@ class TriggerLoader(LazyLogging):
|
|||||||
self._on_stop_requested = False
|
self._on_stop_requested = False
|
||||||
self.triggers: list[Trigger] = []
|
self.triggers: list[Trigger] = []
|
||||||
|
|
||||||
|
def __del__(self) -> None:
|
||||||
|
"""
|
||||||
|
custom destructor object which calls on_stop in case if it was requested
|
||||||
|
"""
|
||||||
|
if not self._on_stop_requested:
|
||||||
|
return
|
||||||
|
self.on_stop()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load(cls, repository_id: RepositoryId, configuration: Configuration) -> Self:
|
def load(cls, repository_id: RepositoryId, configuration: Configuration) -> Self:
|
||||||
"""
|
"""
|
||||||
@ -257,11 +265,3 @@ class TriggerLoader(LazyLogging):
|
|||||||
for trigger in self.triggers:
|
for trigger in self.triggers:
|
||||||
with self.__execute_trigger(trigger):
|
with self.__execute_trigger(trigger):
|
||||||
trigger.on_stop()
|
trigger.on_stop()
|
||||||
|
|
||||||
def __del__(self) -> None:
|
|
||||||
"""
|
|
||||||
custom destructor object which calls on_stop in case if it was requested
|
|
||||||
"""
|
|
||||||
if not self._on_stop_requested:
|
|
||||||
return
|
|
||||||
self.on_stop()
|
|
||||||
|
Loading…
Reference in New Issue
Block a user