From 2ca6134151cc35c987afcbea977db2eb6d9d5c69 Mon Sep 17 00:00:00 2001 From: Greg Leonard <45019882+greg-el@users.noreply.github.com> Date: Wed, 21 Aug 2024 15:34:07 +0100 Subject: [PATCH] Replace `|` with `Union` --- snowplow_tracker/events/structured_event.py | 6 +++--- snowplow_tracker/tracker.py | 14 ++++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/snowplow_tracker/events/structured_event.py b/snowplow_tracker/events/structured_event.py index a904bc1a..4c2d5c2b 100644 --- a/snowplow_tracker/events/structured_event.py +++ b/snowplow_tracker/events/structured_event.py @@ -15,7 +15,7 @@ # language governing permissions and limitations there under. # """ from snowplow_tracker.events.event import Event -from typing import Optional, List +from typing import Optional, List, Union from snowplow_tracker.subject import Subject from snowplow_tracker.self_describing_json import SelfDescribingJson from snowplow_tracker.contracts import non_empty_string @@ -129,12 +129,12 @@ def property_(self, value: str): self.payload.add("se_pr", value) @property - def value(self) -> Optional[int | float]: + def value(self) -> Optional[Union[int, float]]: """ A value associated with the user action """ return self.payload.nv_pairs.get("se_va") @value.setter - def value(self, value: int | float): + def value(self, value: Union[int, float]): self.payload.add("se_va", value) diff --git a/snowplow_tracker/tracker.py b/snowplow_tracker/tracker.py index 0fad3469..4d0b6e00 100644 --- a/snowplow_tracker/tracker.py +++ b/snowplow_tracker/tracker.py @@ -363,7 +363,7 @@ def track_add_to_cart( ) non_empty_string(sku) - properties: dict[str, str | float | int] = {} + properties: Union[dict[str, Union[str, float, int]]] = {} properties["sku"] = sku properties["quantity"] = quantity if name is not None: @@ -427,7 +427,7 @@ def track_remove_from_cart( ) non_empty_string(sku) - properties: dict[str, str | float | int] = {} + properties: dict[str, Union[str, float, int]] = {} properties["sku"] = sku properties["quantity"] = quantity if name is not None: @@ -495,7 +495,7 @@ def track_form_change( if type_ is not None: one_of(type_.lower(), FORM_TYPES) - properties: dict[str, Optional[str] | ElementClasses] = dict() + properties: dict[str, Union[Optional[str], ElementClasses]] = dict() properties["formId"] = form_id properties["elementId"] = element_id properties["nodeName"] = node_name @@ -552,7 +552,7 @@ def track_form_submit( form_element(element) properties: dict[ - str, str | ElementClasses | FormClasses | List[Dict[str, Any]] + str, Union[str, ElementClasses, FormClasses, List[Dict[str, Any]]] ] = dict() properties["formId"] = form_id if form_classes is not None: @@ -606,7 +606,9 @@ def track_site_search( ) non_empty(terms) - properties: dict[str, Sequence[str] | dict[str, str | bool] | int] = {} + properties: Union[ + dict[str, Sequence[str], dict[str, Union[str, bool]], int] + ] = {} properties["terms"] = terms if filters is not None: properties["filters"] = filters @@ -882,7 +884,7 @@ def track_struct_event( action: str, label: Optional[str] = None, property_: Optional[str] = None, - value: Optional[int | float] = None, + value: Optional[Union[int, float]] = None, context: Optional[List[SelfDescribingJson]] = None, tstamp: Optional[float] = None, event_subject: Optional[Subject] = None,