Skip to content

Commit c118d1e

Browse files
author
Matias Melograno
committed
code improvements for properties
1 parent 36bbe89 commit c118d1e

File tree

6 files changed

+12
-25
lines changed

6 files changed

+12
-25
lines changed

splitio/api/events.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@ def _build_bulk(events):
4545
'value': event.value,
4646
'timestamp': event.timestamp,
4747
'properties': event.properties,
48-
} if event.properties is not None else {
49-
'key': event.key,
50-
'trafficTypeName': event.traffic_type_name,
51-
'eventTypeId': event.event_type_id,
52-
'value': event.value,
53-
'timestamp': event.timestamp,
5448
}
5549
for event in events
5650
]

splitio/client/factory.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from splitio.client import util
1616
from splitio.client.listener import ImpressionListenerWrapper
1717

18-
#Storage
18+
# Storage
1919
from splitio.storage.inmemmory import InMemorySplitStorage, InMemorySegmentStorage, \
2020
InMemoryImpressionStorage, InMemoryEventStorage, InMemoryTelemetryStorage
2121
from splitio.storage.adapters import redis
@@ -59,10 +59,10 @@ class TimeoutException(Exception):
5959
pass
6060

6161

62-
class SplitFactory(object): #pylint: disable=too-many-instance-attributes
62+
class SplitFactory(object): # pylint: disable=too-many-instance-attributes
6363
"""Split Factory/Container class."""
6464

65-
def __init__( #pylint: disable=too-many-arguments
65+
def __init__( # pylint: disable=too-many-arguments
6666
self,
6767
storages,
6868
labels_enabled,
@@ -223,7 +223,7 @@ def _wrap_impression_listener(listener, metadata):
223223
return None
224224

225225

226-
def _build_in_memory_factory(api_key, config, sdk_url=None, events_url=None): #pylint: disable=too-many-locals
226+
def _build_in_memory_factory(api_key, config, sdk_url=None, events_url=None): # pylint: disable=too-many-locals
227227
"""Build and return a split factory tailored to the supplied config."""
228228
if not input_validator.validate_factory_instantiation(api_key):
229229
return None
@@ -304,8 +304,8 @@ def _build_in_memory_factory(api_key, config, sdk_url=None, events_url=None): #
304304
tasks['events'].start()
305305
tasks['telemetry'].start()
306306

307-
storages['events'].set_queue_full_hook(tasks['events'].flush())
308-
storages['impressions'].set_queue_full_hook(tasks['impressions'].flush())
307+
storages['events'].set_queue_full_hook(tasks['events'].flush)
308+
storages['impressions'].set_queue_full_hook(tasks['impressions'].flush)
309309

310310
def split_ready_task():
311311
"""Wait for splits to be ready and start fetching segments."""

splitio/client/input_validator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ def valid_properties(properties):
487487

488488
valid_properties = dict()
489489

490-
for property, element in properties.items():
490+
for property, element in six.iteritems(properties):
491491
if not isinstance(property, six.string_types): # Exclude property if is not string
492492
continue
493493

@@ -517,4 +517,4 @@ def valid_properties(properties):
517517
if len(valid_properties.keys()) > 300:
518518
_LOGGER.warning('Event has more than 300 properties. Some of them will be trimmed' +
519519
' when processed')
520-
return True, valid_properties if len(valid_properties.keys()) > 0 else None, size
520+
return True, valid_properties if len(valid_properties) else None, size

splitio/engine/evaluator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
CONTROL = 'control'
88

99

10-
class Evaluator(object): #pylint: disable=too-few-public-methods
10+
class Evaluator(object): # pylint: disable=too-few-public-methods
1111
"""Split Evaluator class."""
1212

1313
def __init__(self, split_storage, segment_storage, splitter):

splitio/storage/uwsgi.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -458,13 +458,6 @@ def pop_many(self, count):
458458
event['value'],
459459
event['timestamp'],
460460
event['properties']
461-
) if 'properties' in event else
462-
Event(
463-
event['key'],
464-
event['traffic_type_name'],
465-
event['event_type_id'],
466-
event['value'],
467-
event['timestamp'],
468461
)
469462
for event in current[:count]
470463
]

tests/api/test_events.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ def test_post_events(self, mocker):
3636

3737
# validate key-value args (body)
3838
assert call_made[2]['body'] == [
39-
{'key': 'k1', 'trafficTypeName': 'user', 'eventTypeId': 'purchase', 'value': 12.50, 'timestamp': 123456},
40-
{'key': 'k2', 'trafficTypeName': 'user', 'eventTypeId': 'purchase', 'value': 12.50, 'timestamp': 123456},
39+
{'key': 'k1', 'trafficTypeName': 'user', 'eventTypeId': 'purchase', 'value': 12.50, 'timestamp': 123456, 'properties': None},
40+
{'key': 'k2', 'trafficTypeName': 'user', 'eventTypeId': 'purchase', 'value': 12.50, 'timestamp': 123456, 'properties': None},
4141
{'key': 'k3', 'trafficTypeName': 'user', 'eventTypeId': 'purchase', 'value': None, 'timestamp': 123456, 'properties': {"test": 1234}},
42-
{'key': 'k4', 'trafficTypeName': 'user', 'eventTypeId': 'purchase', 'value': None, 'timestamp': 123456}
42+
{'key': 'k4', 'trafficTypeName': 'user', 'eventTypeId': 'purchase', 'value': None, 'timestamp': 123456, 'properties': None},
4343
]
4444

4545
httpclient.reset_mock()

0 commit comments

Comments
 (0)