Skip to content

Commit 5bcd094

Browse files
author
Sergio García Prado
committed
ISSUE #198
* Rename classes to increase naming consistency.
1 parent acd8727 commit 5bcd094

File tree

13 files changed

+100
-106
lines changed

13 files changed

+100
-106
lines changed

packages/core/minos-microservice-saga/minos/saga/__init__.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,28 @@
99
)
1010
from .definitions import (
1111
ConditionalSagaStep,
12-
ConditionalSagaStepMeta,
13-
ConditionalSagaStepWrapper,
12+
ConditionalSagaStepDecoratorMeta,
13+
ConditionalSagaStepDecoratorWrapper,
1414
ElseThenAlternative,
1515
ElseThenAlternativeMeta,
1616
ElseThenAlternativeWrapper,
1717
IfThenAlternative,
1818
IfThenAlternativeMeta,
1919
IfThenAlternativeWrapper,
2020
LocalSagaStep,
21-
LocalSagaStepMeta,
22-
LocalSagaStepWrapper,
23-
OnStepDecorator,
21+
LocalSagaStepDecoratorMeta,
22+
LocalSagaStepDecoratorWrapper,
23+
OnSagaStepDecorator,
2424
RemoteSagaStep,
25-
RemoteSagaStepMeta,
26-
RemoteSagaStepWrapper,
25+
RemoteSagaStepDecoratorMeta,
26+
RemoteSagaStepDecoratorWrapper,
2727
Saga,
28-
SagaClassMeta,
29-
SagaClassWrapper,
28+
SagaDecoratorMeta,
29+
SagaDecoratorWrapper,
3030
SagaOperation,
3131
SagaStep,
32-
SagaStepMeta,
33-
SagaStepWrapper,
32+
SagaStepDecoratorMeta,
33+
SagaStepDecoratorWrapper,
3434
)
3535
from .exceptions import (
3636
AlreadyCommittedException,

packages/core/minos-microservice-saga/minos/saga/definitions/__init__.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,29 @@
33
)
44
from .saga import (
55
Saga,
6-
SagaClassMeta,
7-
SagaClassWrapper,
6+
SagaDecoratorMeta,
7+
SagaDecoratorWrapper,
88
)
99
from .steps import (
1010
ConditionalSagaStep,
11-
ConditionalSagaStepMeta,
12-
ConditionalSagaStepWrapper,
11+
ConditionalSagaStepDecoratorMeta,
12+
ConditionalSagaStepDecoratorWrapper,
1313
ElseThenAlternative,
1414
ElseThenAlternativeMeta,
1515
ElseThenAlternativeWrapper,
1616
IfThenAlternative,
1717
IfThenAlternativeMeta,
1818
IfThenAlternativeWrapper,
1919
LocalSagaStep,
20-
LocalSagaStepMeta,
21-
LocalSagaStepWrapper,
22-
OnStepDecorator,
20+
LocalSagaStepDecoratorMeta,
21+
LocalSagaStepDecoratorWrapper,
22+
OnSagaStepDecorator,
2323
RemoteSagaStep,
24-
RemoteSagaStepMeta,
25-
RemoteSagaStepWrapper,
24+
RemoteSagaStepDecoratorMeta,
25+
RemoteSagaStepDecoratorWrapper,
2626
SagaStep,
27-
SagaStepMeta,
28-
SagaStepWrapper,
27+
SagaStepDecoratorMeta,
28+
SagaStepDecoratorWrapper,
2929
)
3030
from .types import (
3131
ConditionCallback,

packages/core/minos-microservice-saga/minos/saga/definitions/saga.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,37 +37,35 @@
3737
LocalSagaStep,
3838
RemoteSagaStep,
3939
SagaStep,
40-
SagaStepWrapper,
40+
SagaStepDecoratorWrapper,
4141
)
4242
from .types import (
4343
LocalCallback,
4444
RequestCallBack,
4545
)
4646

47-
SagaClass = TypeVar("SagaClass", bound=type)
48-
4947

5048
@runtime_checkable
51-
class SagaClassWrapper(Protocol):
49+
class SagaDecoratorWrapper(Protocol):
5250
"""TODO"""
5351

54-
meta: SagaClassMeta
52+
meta: SagaDecoratorMeta
5553

5654

57-
class SagaClassMeta:
55+
class SagaDecoratorMeta:
5856
"""TODO"""
5957

60-
_class: SagaClass
58+
_inner: type
6159
_definition: Saga
6260

63-
def __init__(self, func: SagaClass, saga: Saga):
64-
self._class = func
61+
def __init__(self, func: type, saga: Saga):
62+
self._inner = func
6563
self._definition = saga
6664

6765
@cached_property
6866
def definition(self) -> Saga:
6967
"""TODO"""
70-
steps = getmembers(self._class, predicate=lambda x: isinstance(x, SagaStepWrapper))
68+
steps = getmembers(self._inner, predicate=lambda x: isinstance(x, SagaStepDecoratorWrapper))
7169
steps = list(map(lambda member: member[1].meta.definition, steps))
7270
for step in steps:
7371
if step.order is None:
@@ -111,8 +109,8 @@ def __init__(
111109
self.local_step(commit)
112110
self.committed = True
113111

114-
def __call__(self, type_: TP) -> Union[TP, SagaClassWrapper]:
115-
type_.meta = SagaClassMeta(type_, self)
112+
def __call__(self, type_: TP) -> Union[TP, SagaDecoratorWrapper]:
113+
type_.meta = SagaDecoratorMeta(type_, self)
116114
return type_
117115

118116
@classmethod
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from .abc import (
2-
OnStepDecorator,
2+
OnSagaStepDecorator,
33
SagaStep,
4-
SagaStepMeta,
5-
SagaStepWrapper,
4+
SagaStepDecoratorMeta,
5+
SagaStepDecoratorWrapper,
66
)
77
from .conditional import (
88
ConditionalSagaStep,
9-
ConditionalSagaStepMeta,
10-
ConditionalSagaStepWrapper,
9+
ConditionalSagaStepDecoratorMeta,
10+
ConditionalSagaStepDecoratorWrapper,
1111
ElseThenAlternative,
1212
ElseThenAlternativeMeta,
1313
ElseThenAlternativeWrapper,
@@ -17,11 +17,11 @@
1717
)
1818
from .local import (
1919
LocalSagaStep,
20-
LocalSagaStepMeta,
21-
LocalSagaStepWrapper,
20+
LocalSagaStepDecoratorMeta,
21+
LocalSagaStepDecoratorWrapper,
2222
)
2323
from .remote import (
2424
RemoteSagaStep,
25-
RemoteSagaStepMeta,
26-
RemoteSagaStepWrapper,
25+
RemoteSagaStepDecoratorMeta,
26+
RemoteSagaStepDecoratorWrapper,
2727
)

packages/core/minos-microservice-saga/minos/saga/definitions/steps/abc.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,21 @@
4444
RemoteSagaStep,
4545
)
4646

47-
T = TypeVar("T")
48-
4947

5048
@runtime_checkable
51-
class SagaStepWrapper(Protocol):
49+
class SagaStepDecoratorWrapper(Protocol):
5250
"""TODO"""
5351

54-
meta: SagaStepMeta
52+
meta: SagaStepDecoratorMeta
5553

5654

57-
class SagaStepMeta:
55+
class SagaStepDecoratorMeta:
5856
"""TODO"""
5957

60-
_inner: T
58+
_inner: Any
6159
_definition: SagaStep
6260

63-
def __init__(self, inner: T, definition: SagaStep):
61+
def __init__(self, inner: Any, definition: SagaStep):
6462
self._inner = inner
6563
self._definition = definition
6664

@@ -73,10 +71,10 @@ def definition(self) -> SagaStep:
7371
FN = TypeVar("FN", bound=Callable)
7472

7573

76-
class OnStepDecorator(Generic[FN]):
74+
class OnSagaStepDecorator(Generic[FN]):
7775
""" "TODO"""
7876

79-
def __init__(self, attr_name: [str] = None, step_meta: Optional[SagaStepMeta] = None):
77+
def __init__(self, attr_name: [str] = None, step_meta: Optional[SagaStepDecoratorMeta] = None):
8078
if attr_name is None or step_meta is None:
8179
raise ValueError("TODO")
8280
self.step_meta = step_meta
@@ -124,7 +122,7 @@ def _from_raw(cls, raw: dict[str, Any]) -> SagaStep:
124122
raise NotImplementedError
125123

126124
@abstractmethod
127-
def __call__(self, func: Callable) -> SagaStepWrapper:
125+
def __call__(self, func: Callable) -> SagaStepDecoratorWrapper:
128126
"""TODO"""
129127

130128
def conditional_step(self, *args, **kwargs) -> ConditionalSagaStep:

packages/core/minos-microservice-saga/minos/saga/definitions/steps/conditional.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,25 @@
4242
)
4343
from .abc import (
4444
SagaStep,
45-
SagaStepMeta,
46-
SagaStepWrapper,
45+
SagaStepDecoratorMeta,
46+
SagaStepDecoratorWrapper,
4747
)
4848

4949
if TYPE_CHECKING:
5050
from ..saga import (
5151
Saga,
5252
)
5353

54-
TP = TypeVar("TP", bound=type)
54+
ConditionalSagaStepClass = TypeVar("ConditionalSagaStepClass", bound=type)
5555

5656

57-
class ConditionalSagaStepWrapper(SagaStepWrapper):
57+
class ConditionalSagaStepDecoratorWrapper(SagaStepDecoratorWrapper):
5858
"""TODO"""
5959

60-
meta: ConditionalSagaStepMeta
60+
meta: ConditionalSagaStepDecoratorMeta
6161

6262

63-
class ConditionalSagaStepMeta(SagaStepMeta):
63+
class ConditionalSagaStepDecoratorMeta(SagaStepDecoratorMeta):
6464
"""TODO"""
6565

6666
_definition: ConditionalSagaStep
@@ -80,8 +80,9 @@ def definition(self):
8080

8181
else_then_alternatives = getmembers(
8282
self._inner,
83-
predicate=lambda x: isinstance(x, ElseThenAlternativeWrapper)
84-
and isinstance(x.meta, ElseThenAlternativeMeta),
83+
predicate=(
84+
lambda x: isinstance(x, ElseThenAlternativeWrapper) and isinstance(x.meta, ElseThenAlternativeMeta)
85+
),
8586
)
8687
else_then_alternatives = list(map(lambda member: member[1].meta.alternative, else_then_alternatives))
8788
if len(else_then_alternatives) > 1:
@@ -130,8 +131,8 @@ def _from_raw(cls, raw: dict[str, Any], **kwargs) -> ConditionalSagaStep:
130131

131132
return cls(**current)
132133

133-
def __call__(self, type_: TP) -> Union[TP, ConditionalSagaStepMeta]:
134-
meta = ConditionalSagaStepMeta(type_, self)
134+
def __call__(self, type_: ConditionalSagaStepClass) -> ConditionalSagaStepClass:
135+
meta = ConditionalSagaStepDecoratorMeta(type_, self)
135136
type_.meta = meta
136137
return type_
137138

packages/core/minos-microservice-saga/minos/saga/definitions/steps/local.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,22 @@
3838
LocalCallback,
3939
)
4040
from .abc import (
41-
OnStepDecorator,
41+
OnSagaStepDecorator,
4242
SagaStep,
43-
SagaStepMeta,
44-
SagaStepWrapper,
43+
SagaStepDecoratorMeta,
44+
SagaStepDecoratorWrapper,
4545
)
4646

4747

48-
class LocalSagaStepWrapper(SagaStepWrapper):
48+
class LocalSagaStepDecoratorWrapper(SagaStepDecoratorWrapper):
4949
"""TODO"""
5050

51-
meta: LocalSagaStepMeta
52-
on_failure: type[OnStepDecorator[LocalCallback]]
51+
meta: LocalSagaStepDecoratorMeta
52+
on_failure: type[OnSagaStepDecorator[LocalCallback]]
5353
__call__: LocalCallback
5454

5555

56-
class LocalSagaStepMeta(SagaStepMeta):
56+
class LocalSagaStepDecoratorMeta(SagaStepDecoratorMeta):
5757
"""TODO"""
5858

5959
_definition: LocalSagaStep
@@ -72,10 +72,10 @@ def definition(self):
7272
return self._definition
7373

7474
@cached_property
75-
def on_failure(self) -> OnStepDecorator:
75+
def on_failure(self) -> OnSagaStepDecorator:
7676
"""TODO"""
7777
# noinspection PyTypeChecker
78-
return partial(OnStepDecorator, step_meta=self, attr_name="_on_failure")
78+
return partial(OnSagaStepDecorator, step_meta=self, attr_name="_on_failure")
7979

8080

8181
class LocalSagaStep(SagaStep):
@@ -105,8 +105,8 @@ def _from_raw(cls, raw: dict[str, Any]) -> LocalSagaStep:
105105

106106
return cls(**raw)
107107

108-
def __call__(self, func: LocalCallback) -> LocalSagaStepWrapper:
109-
meta = LocalSagaStepMeta(func, self)
108+
def __call__(self, func: LocalCallback) -> LocalSagaStepDecoratorWrapper:
109+
meta = LocalSagaStepDecoratorMeta(func, self)
110110
func.meta = meta
111111
func.on_failure = meta.on_failure
112112
# noinspection PyTypeChecker

0 commit comments

Comments
 (0)