Skip to content

Commit 80c4a9f

Browse files
committed
style:
1 parent 1c25508 commit 80c4a9f

File tree

18 files changed

+66
-52
lines changed

18 files changed

+66
-52
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ qa: analyze test
33
analyze:
44
@poetry run pylint eventsourcingdb_client_python tests
55

6+
fix:
7+
@poetry run autopep8 --in-place --aggressive --max-line-length=100 --recursive eventsourcingdb_client_python tests
8+
69
test:
710
@poetry run pytest --maxfail=1
811

912
clean:
1013

1114
build: qa clean
1215

13-
.PHONY: analyze build clean qa test
16+
.PHONY: fix analyze build clean qa test

eventsourcingdb_client_python/event/event.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# due to its business context. Splitting it into smaller
1212
# methods would increase cognitive load and make the
1313
# code less readable.
14+
15+
1416
class Event(EventContext):
1517
def __init__(
1618
self,

eventsourcingdb_client_python/handlers/is_event.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ def is_event(message: Any) -> bool:
88
if isinstance(message, dict) and message.get('type') == EVENT_TYPE:
99
payload = message.get('payload')
1010
return isinstance(payload, dict) and isinstance(payload.get('hash'), str)
11-
11+
1212
# Otherwise check for old format (just for backward compatibility)
1313
if not isinstance(message, dict):
1414
return False
15-
15+
1616
payload = message.get('payload')
1717
return (
1818
isinstance(payload, dict)

eventsourcingdb_client_python/handlers/lower_bound.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from eventsourcingdb_client_python.errors.invalid_parameter_error import InvalidParameterError
44

5-
# TODO: id must be a string.
5+
66
@dataclass
77
class LowerBound:
88
id: str
@@ -14,9 +14,8 @@ def __post_init__(self):
1414
parameter_name="LowerBound",
1515
reason='type must be either "inclusive" or "exclusive"'
1616
)
17-
1817
if int(self.id) < 0:
1918
raise InvalidParameterError(
2019
parameter_name='LowerBound',
2120
reason='id must be non-negative'
22-
)
21+
)

eventsourcingdb_client_python/handlers/observe_events/observe_events.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
# for better readability. Even though it is not necessary,
2424
# it makes the return type clear without needing to read any
2525
# documentation or code.
26+
27+
2628
async def observe_events(
2729
client: AbstractBaseClient,
2830
subject: str,
@@ -77,13 +79,19 @@ async def observe_events(
7779
event = Event.parse(message['payload'])
7880
# Add client-side filtering by event ID
7981
event_id = int(message['payload']['id'])
80-
82+
8183
if options.lower_bound is not None:
8284
# For inclusive, include events with ID >= lower bound
83-
if options.lower_bound.type == 'inclusive' and event_id < options.lower_bound.id:
85+
if (
86+
options.lower_bound.type == 'inclusive' and # pylint: disable=R2004
87+
int(event_id) < int(options.lower_bound.id)
88+
):
8489
continue
8590
# For exclusive, include events with ID > lower bound
86-
if options.lower_bound.type == 'exclusive' and event_id <= options.lower_bound.id:
91+
if (
92+
options.lower_bound.type == 'exclusive' and # pylint: disable=R2004
93+
int(event_id) <= int(options.lower_bound.id)
94+
):
8795
continue
8896

8997
yield StoreItem(event, message['payload']['hash'])

eventsourcingdb_client_python/handlers/observe_events/observe_events_options.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
from ...errors.validation_error import ValidationError
55
from ...event.validate_subject import validate_subject
66
from ...event.validate_type import validate_type
7-
from ...util.is_non_negativ_integer import is_non_negative_integer
87
from .observe_from_latest_event import ObserveFromLatestEvent
98

9+
1010
@dataclass
1111
class ObserveEventsOptions:
1212
recursive: bool
@@ -19,7 +19,7 @@ def validate(self) -> None:
1919
raise ValidationError(
2020
'ObserveEventsOptions are invalid: lower_bound must be a LowerBound object.'
2121
)
22-
22+
2323
if self.from_latest_event is not None:
2424
if self.lower_bound is not None:
2525
raise ValidationError(
@@ -43,7 +43,6 @@ def validate(self) -> None:
4343
f'Failed to validate \'from_latest_event\': {str(validation_error)}'
4444
) from validation_error
4545

46-
4746
def to_json(self):
4847
json = {
4948
'recursive': self.recursive
@@ -55,8 +54,8 @@ def to_json(self):
5554
'id': str(self.lower_bound.id), # Ensure ID is a string
5655
'type': self.lower_bound.type
5756
}
58-
57+
5958
if self.from_latest_event is not None:
6059
json['fromLatestEvent'] = self.from_latest_event.to_json()
6160

62-
return json
61+
return json

eventsourcingdb_client_python/handlers/read_event_types/read_event_types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
# for better readability. Even though it is not necessary,
1818
# it makes the return type clear without needing to read any
1919
# documentation or code.
20+
21+
2022
async def read_event_types(
2123
client: AbstractBaseClient,
2224
) -> AsyncGenerator[EventType, None]:

eventsourcingdb_client_python/handlers/read_events/read_events.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
# for better readability. Even though it is not necessary,
2323
# it makes the return type clear without needing to read any
2424
# documentation or code.
25+
26+
2527
async def read_events(
2628
client: AbstractBaseClient,
2729
subject: str,
@@ -71,28 +73,40 @@ async def read_events(
7173

7274
if is_event(message):
7375
event = Event.parse(message['payload'])
74-
76+
7577
event_id = int(message['payload']['id']) # Access ID from raw payload
7678

7779
if options.lower_bound is not None:
7880
# For inclusive, include events with ID >= lower bound
79-
if options.lower_bound.type == 'inclusive' and event_id < options.lower_bound.id:
81+
if (
82+
options.lower_bound.type == 'inclusive' and # pylint: disable=R2004
83+
int(event_id) < int(options.lower_bound.id)
84+
):
8085
continue
8186
# For exclusive, include events with ID > lower bound
82-
if options.lower_bound.type == 'exclusive' and event_id <= options.lower_bound.id:
87+
if (
88+
options.lower_bound.type == 'exclusive' and # pylint: disable=R2004
89+
int(event_id) <= int(options.lower_bound.id)
90+
):
8391
continue
84-
92+
8593
if options.upper_bound is not None:
8694
# For inclusive, include events with ID <= upper bound
87-
if options.upper_bound.type == 'inclusive' and event_id > options.upper_bound.id:
95+
if (
96+
options.upper_bound.type == 'inclusive' and # pylint: disable=R2004
97+
int(event_id) > int(options.upper_bound.id)
98+
):
8899
continue
89100
# For exclusive, include events with ID < upper bound
90-
if options.upper_bound.type == 'exclusive' and event_id >= options.upper_bound.id:
101+
if (
102+
options.upper_bound.type == 'exclusive' and # pylint: disable=R2004
103+
int(event_id) >= int(options.upper_bound.id)
104+
):
91105
continue
92106

93107
yield StoreItem(event, message['payload']['hash'])
94108
continue
95-
109+
96110
raise ServerError(
97111
f'Failed to read events, an unexpected stream item was received: '
98112
f'{message}.'

eventsourcingdb_client_python/handlers/read_events/read_events_options.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from .order import Order
66
from ...errors.validation_error import ValidationError
77
from ...event.validate_subject import validate_subject
8-
from ...event.validate_type import validate_type
98
from .read_from_latest_event import ReadFromLatestEvent
109

1110

@@ -23,7 +22,7 @@ def validate(self) -> None:
2322
raise ValidationError(
2423
'ReadEventOptions are invalid: lower_bound must be a LowerBound object.'
2524
)
26-
25+
2726
if self.upper_bound is not None and not isinstance(self.upper_bound, UpperBound):
2827
raise ValidationError(
2928
'ReadEventOptions are invalid: upper_bound must be a UpperBound object.'
@@ -58,21 +57,21 @@ def to_json(self):
5857

5958
if self.order is not None:
6059
json['order'] = self.order.value
61-
60+
6261
# Directly use the objects
6362
if self.lower_bound is not None:
6463
json['lowerBound'] = {
6564
'id': str(self.lower_bound.id), # Ensure ID is a string
6665
'type': self.lower_bound.type
6766
}
68-
67+
6968
if self.upper_bound is not None:
7069
json['upperBound'] = {
7170
'id': str(self.upper_bound.id), # Ensure ID is a string
7271
'type': self.upper_bound.type
7372
}
74-
73+
7574
if self.from_latest_event is not None:
7675
json['fromLatestEvent'] = self.from_latest_event.to_json()
7776

78-
return json
77+
return json

eventsourcingdb_client_python/handlers/read_subjects/read_subjects.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
# for better readability. Even though it is not necessary,
2020
# it makes the return type clear without needing to read any
2121
# documentation or code.
22+
23+
2224
async def read_subjects(
2325
client: AbstractBaseClient,
2426
base_subject: str

0 commit comments

Comments
 (0)