Skip to content

Commit d0d962a

Browse files
hjoaquimneilkakkar
andauthored
Module functions to also return the same as its Client equivalent (#111)
Co-authored-by: Neil Kakkar <[email protected]>
1 parent e348106 commit d0d962a

File tree

4 files changed

+29
-17
lines changed

4 files changed

+29
-17
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 3.3.2 - 2024-01-19
2+
3+
1. Return success/failure with all capture calls from module functions
4+
5+
16
## 3.3.1 - 2024-01-10
27

38
1. Make sure we don't override any existing feature flag properties when adding locally evaluated feature flag properties.

posthog/__init__.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import datetime # noqa: F401
2-
from typing import Callable, Dict, Optional # noqa: F401
2+
from typing import Callable, Dict, Optional, Tuple # noqa: F401
33

44
from posthog.client import Client
55
from posthog.version import VERSION
@@ -33,7 +33,7 @@ def capture(
3333
send_feature_flags=False,
3434
disable_geoip=None, # type: Optional[bool]
3535
):
36-
# type: (...) -> None
36+
# type: (...) -> Tuple[bool, dict]
3737
"""
3838
Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up.
3939
@@ -54,7 +54,7 @@ def capture(
5454
posthog.capture('distinct id', 'purchase', groups={'company': 'id:5'})
5555
```
5656
"""
57-
_proxy(
57+
return _proxy(
5858
"capture",
5959
distinct_id=distinct_id,
6060
event=event,
@@ -76,7 +76,7 @@ def identify(
7676
uuid=None, # type: Optional[str]
7777
disable_geoip=None, # type: Optional[bool]
7878
):
79-
# type: (...) -> None
79+
# type: (...) -> Tuple[bool, dict]
8080
"""
8181
Identify lets you add metadata on your users so you can more easily identify who they are in PostHog, and even do things like segment users by these properties.
8282
@@ -92,7 +92,7 @@ def identify(
9292
})
9393
```
9494
"""
95-
_proxy(
95+
return _proxy(
9696
"identify",
9797
distinct_id=distinct_id,
9898
properties=properties,
@@ -111,7 +111,7 @@ def set(
111111
uuid=None, # type: Optional[str]
112112
disable_geoip=None, # type: Optional[bool]
113113
):
114-
# type: (...) -> None
114+
# type: (...) -> Tuple[bool, dict]
115115
"""
116116
Set properties on a user record.
117117
This will overwrite previous people property values, just like `identify`.
@@ -127,7 +127,7 @@ def set(
127127
})
128128
```
129129
"""
130-
_proxy(
130+
return _proxy(
131131
"set",
132132
distinct_id=distinct_id,
133133
properties=properties,
@@ -146,7 +146,7 @@ def set_once(
146146
uuid=None, # type: Optional[str]
147147
disable_geoip=None, # type: Optional[bool]
148148
):
149-
# type: (...) -> None
149+
# type: (...) -> Tuple[bool, dict]
150150
"""
151151
Set properties on a user record, only if they do not yet exist.
152152
This will not overwrite previous people property values, unlike `identify`.
@@ -162,7 +162,7 @@ def set_once(
162162
})
163163
```
164164
"""
165-
_proxy(
165+
return _proxy(
166166
"set_once",
167167
distinct_id=distinct_id,
168168
properties=properties,
@@ -182,7 +182,7 @@ def group_identify(
182182
uuid=None, # type: Optional[str]
183183
disable_geoip=None, # type: Optional[bool]
184184
):
185-
# type: (...) -> None
185+
# type: (...) -> Tuple[bool, dict]
186186
"""
187187
Set properties on a group
188188
@@ -198,7 +198,7 @@ def group_identify(
198198
})
199199
```
200200
"""
201-
_proxy(
201+
return _proxy(
202202
"group_identify",
203203
group_type=group_type,
204204
group_key=group_key,
@@ -218,7 +218,7 @@ def alias(
218218
uuid=None, # type: Optional[str]
219219
disable_geoip=None, # type: Optional[bool]
220220
):
221-
# type: (...) -> None
221+
# type: (...) -> Tuple[bool, dict]
222222
"""
223223
To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like "Which marketing channels leads to users churning after a month?" or "What do users do on our website before signing up?"
224224
@@ -235,7 +235,7 @@ def alias(
235235
posthog.alias('anonymous session id', 'distinct id')
236236
```
237237
"""
238-
_proxy(
238+
return _proxy(
239239
"alias",
240240
previous_id=previous_id,
241241
distinct_id=distinct_id,

posthog/test/test_module.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
class TestModule(unittest.TestCase):
77
posthog = None
88

9+
def _assert_enqueue_result(self, result):
10+
self.assertEqual(type(result[0]), bool)
11+
self.assertEqual(type(result[1]), dict)
12+
913
def failed(self):
1014
self.failed = True
1115

@@ -22,15 +26,18 @@ def test_no_host(self):
2226
self.assertRaises(Exception, self.posthog.capture)
2327

2428
def test_track(self):
25-
self.posthog.capture("distinct_id", "python module event")
29+
res = self.posthog.capture("distinct_id", "python module event")
30+
self._assert_enqueue_result(res)
2631
self.posthog.flush()
2732

2833
def test_identify(self):
29-
self.posthog.identify("distinct_id", {"email": "[email protected]"})
34+
res = self.posthog.identify("distinct_id", {"email": "[email protected]"})
35+
self._assert_enqueue_result(res)
3036
self.posthog.flush()
3137

3238
def test_alias(self):
33-
self.posthog.alias("previousId", "distinct_id")
39+
res = self.posthog.alias("previousId", "distinct_id")
40+
self._assert_enqueue_result(res)
3441
self.posthog.flush()
3542

3643
def test_page(self):

posthog/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION = "3.3.1"
1+
VERSION = "3.3.2"
22

33
if __name__ == "__main__":
44
print(VERSION, end="") # noqa: T201

0 commit comments

Comments
 (0)