Skip to content

Commit 0133032

Browse files
committed
ruff format .
1 parent d0470a3 commit 0133032

File tree

4 files changed

+73
-46
lines changed

4 files changed

+73
-46
lines changed

posthog/client.py

Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,54 @@
1010
from six import string_types
1111
from typing_extensions import Unpack
1212

13-
from posthog.args import (ID_TYPES, ExceptionArg, OptionalCaptureArgs,
14-
OptionalSetArgs)
13+
from posthog.args import ID_TYPES, ExceptionArg, OptionalCaptureArgs, OptionalSetArgs
1514
from posthog.consumer import Consumer
16-
from posthog.contexts import (_get_current_context, get_context_distinct_id,
17-
get_context_session_id, new_context)
15+
from posthog.contexts import (
16+
_get_current_context,
17+
get_context_distinct_id,
18+
get_context_session_id,
19+
new_context,
20+
)
1821
from posthog.exception_capture import ExceptionCapture
19-
from posthog.exception_utils import (exc_info_from_error,
20-
exception_is_already_captured,
21-
exceptions_from_error_tuple,
22-
handle_in_app, mark_exception_as_captured)
23-
from posthog.feature_flags import (InconclusiveMatchError,
24-
match_feature_flag_properties)
22+
from posthog.exception_utils import (
23+
exc_info_from_error,
24+
exception_is_already_captured,
25+
exceptions_from_error_tuple,
26+
handle_in_app,
27+
mark_exception_as_captured,
28+
)
29+
from posthog.feature_flags import InconclusiveMatchError, match_feature_flag_properties
2530
from posthog.poller import Poller
26-
from posthog.request import (DEFAULT_HOST, APIError, batch_post,
27-
determine_server_host, flags, get, remote_config)
28-
from posthog.types import (FeatureFlag, FeatureFlagResult, FlagMetadata,
29-
FlagsAndPayloads, FlagsResponse, FlagValue,
30-
normalize_flags_response, to_flags_and_payloads,
31-
to_payloads, to_values)
32-
from posthog.utils import (FlagCache, RedisFlagCache, SizeLimitedDict, clean,
33-
guess_timezone, remove_trailing_slash,
34-
system_context)
31+
from posthog.request import (
32+
DEFAULT_HOST,
33+
APIError,
34+
batch_post,
35+
determine_server_host,
36+
flags,
37+
get,
38+
remote_config,
39+
)
40+
from posthog.types import (
41+
FeatureFlag,
42+
FeatureFlagResult,
43+
FlagMetadata,
44+
FlagsAndPayloads,
45+
FlagsResponse,
46+
FlagValue,
47+
normalize_flags_response,
48+
to_flags_and_payloads,
49+
to_payloads,
50+
to_values,
51+
)
52+
from posthog.utils import (
53+
FlagCache,
54+
RedisFlagCache,
55+
SizeLimitedDict,
56+
clean,
57+
guess_timezone,
58+
remove_trailing_slash,
59+
system_context,
60+
)
3561
from posthog.version import VERSION
3662

3763
try:
@@ -274,9 +300,9 @@ def feature_flags(self, flags):
274300
for flag in self._feature_flags
275301
if flag.get("key") is not None
276302
}
277-
assert (
278-
self.feature_flags_by_key is not None
279-
), "feature_flags_by_key should be initialized when feature_flags is set"
303+
assert self.feature_flags_by_key is not None, (
304+
"feature_flags_by_key should be initialized when feature_flags is set"
305+
)
280306

281307
def get_feature_variants(
282308
self,
@@ -1435,9 +1461,9 @@ def _locally_evaluate_flag(
14351461
response = None
14361462

14371463
if self.feature_flags:
1438-
assert (
1439-
self.feature_flags_by_key is not None
1440-
), "feature_flags_by_key should be initialized when feature_flags is set"
1464+
assert self.feature_flags_by_key is not None, (
1465+
"feature_flags_by_key should be initialized when feature_flags is set"
1466+
)
14411467
# Local evaluation
14421468
flag = self.feature_flags_by_key.get(key)
14431469
if flag:

posthog/request.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,23 +139,23 @@ def remote_config(
139139
timeout: int = 15,
140140
) -> Any:
141141
"""Get remote config flag value from remote_config API endpoint"""
142-
url = remove_trailing_slash(host or DEFAULT_HOST) + f"/api/projects/@current/feature_flags/{key}/remote_config/"
143-
144-
body = {
145-
"api_key": project_api_key,
146-
"sentAt": datetime.now(tz=tzutc()).isoformat()
147-
}
148-
142+
url = (
143+
remove_trailing_slash(host or DEFAULT_HOST)
144+
+ f"/api/projects/@current/feature_flags/{key}/remote_config/"
145+
)
146+
147+
body = {"api_key": project_api_key, "sentAt": datetime.now(tz=tzutc()).isoformat()}
148+
149149
headers = {
150150
"Authorization": f"Bearer {personal_api_key}",
151151
"Content-Type": "application/json",
152-
"User-Agent": USER_AGENT
152+
"User-Agent": USER_AGENT,
153153
}
154-
154+
155155
data = json.dumps(body, cls=DatetimeSerializer)
156-
156+
157157
res = _session.post(url, data=data, headers=headers, timeout=timeout)
158-
158+
159159
return _process_response(
160160
res,
161161
success_message=f"POST /api/projects/@current/feature_flags/{key}/remote_config/ completed successfully",

posthog/test/test_client.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
from parameterized import parameterized
99

1010
from posthog.client import Client
11-
from posthog.contexts import (get_context_session_id, new_context,
12-
set_context_session)
11+
from posthog.contexts import get_context_session_id, new_context, set_context_session
1312
from posthog.request import APIError
1413
from posthog.test.test_utils import FAKE_TEST_API_KEY
1514
from posthog.types import FeatureFlag, LegacyFlagMetadata
@@ -1924,9 +1923,9 @@ def test_mock_system_context(
19241923

19251924
# Set up platform-specific mocks
19261925
if platform_method:
1927-
getattr(mock_platform, platform_method).return_value = (
1928-
platform_return
1929-
)
1926+
getattr(
1927+
mock_platform, platform_method
1928+
).return_value = platform_return
19301929

19311930
# Special handling for Linux which uses distro module
19321931
if sys_platform == "linux":

remote_config_example.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,29 @@
66
import posthog
77

88
# Initialize PostHog client
9-
#posthog.api_key = "phc_ml85lVi483SwbdDrqgb2LJOSXf050rPNpA6rrz7O5VY"
9+
# posthog.api_key = "phc_ml85lVi483SwbdDrqgb2LJOSXf050rPNpA6rrz7O5VY"
1010
posthog.api_key = "phc_8oSYhZJ7VpjQFNngdkUzEGctbY1u9P3SNJPcAKAhPvE"
1111
posthog.personal_api_key = "phs_QVofStqGt6UUMTlnxKoXb5cHAkQ7JesCZ1PUxfxNRUHKEUx"
1212
# posthog.personal_api_key = "phx_N8hy6HQcO0vplOc16fY2mYRBWVWl8mLDca38LgdmrwT3isA"
1313
posthog.host = "http://localhost:8000"
1414
posthog.debug = True
1515

16+
1617
def test_remote_config():
1718
"""Test remote config payload retrieval."""
1819
print("Testing remote config endpoint...")
19-
20+
2021
# Test feature flag key - replace with an actual flag key from your project
2122
flag_key = "unencrypted-remote-config-setting"
22-
23+
2324
try:
2425
# Get remote config payload
2526
payload = posthog.get_remote_config_payload(flag_key)
2627
print(f"✅ Success! Remote config payload for '{flag_key}': {payload}")
27-
28+
2829
except Exception as e:
2930
print(f"❌ Error getting remote config: {e}")
3031

32+
3133
if __name__ == "__main__":
32-
test_remote_config()
34+
test_remote_config()

0 commit comments

Comments
 (0)