Skip to content

Commit 59c850d

Browse files
committed
fix(analytics): rename analytics rule type to schema to avoid mypy issues
1 parent dd3e286 commit 59c850d

3 files changed

Lines changed: 25 additions & 23 deletions

File tree

src/typesense/analytics_rule.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Per-rule client for Analytics rules operations."""
22

33
from typesense.api_call import ApiCall
4-
from typesense.types.analytics import AnalyticsRule
4+
from typesense.types.analytics import AnalyticsRuleSchema
55

66

77
class AnalyticsRule:
@@ -15,15 +15,15 @@ def _endpoint_path(self) -> str:
1515

1616
return "/".join([AnalyticsRules.resource_path, self.rule_name])
1717

18-
def retrieve(self) -> AnalyticsRule:
18+
def retrieve(self) -> AnalyticsRuleSchema:
1919
response: AnalyticsRule = self.api_call.get(
2020
self._endpoint_path,
2121
as_json=True,
2222
entity_type=AnalyticsRule,
2323
)
2424
return response
2525

26-
def delete(self) -> AnalyticsRule:
26+
def delete(self) -> AnalyticsRuleSchema:
2727
response: AnalyticsRule = self.api_call.delete(
2828
self._endpoint_path,
2929
entity_type=AnalyticsRule,

src/typesense/analytics_rules.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
else:
88
import typing_extensions as typing
99

10+
from typesense.analytics_rule import AnalyticsRule
1011
from typesense.api_call import ApiCall
1112
from typesense.types.analytics import (
12-
AnalyticsRule,
1313
AnalyticsRuleCreate,
14+
AnalyticsRuleSchema,
1415
AnalyticsRuleUpdate,
1516
)
1617

@@ -20,40 +21,42 @@ class AnalyticsRules(object):
2021

2122
def __init__(self, api_call: ApiCall) -> None:
2223
self.api_call = api_call
23-
self.rules: typing.Dict[str, "AnalyticsRule"] = {}
24+
self.rules: typing.Dict[str, AnalyticsRuleSchema] = {}
2425

25-
def __getitem__(self, rule_name: str) -> "AnalyticsRule":
26+
def __getitem__(self, rule_name: str) -> AnalyticsRuleSchema:
2627
if rule_name not in self.rules:
27-
from typesense.analytics_rule import AnalyticsRule as PerRule
28+
self.rules[rule_name] = AnalyticsRule(self.api_call, rule_name)
29+
return self.rules[rule_name]
2830

29-
self.rules[rule_name] = PerRule(self.api_call, rule_name)
30-
return typing.cast("AnalyticsRule", self.rules[rule_name])
31-
32-
def create(self, rule: AnalyticsRuleCreate) -> AnalyticsRule:
33-
response: AnalyticsRule = self.api_call.post(
31+
def create(self, rule: AnalyticsRuleCreate) -> AnalyticsRuleSchema:
32+
response: AnalyticsRuleSchema = self.api_call.post(
3433
AnalyticsRules.resource_path,
3534
body=rule,
3635
as_json=True,
37-
entity_type=AnalyticsRule,
36+
entity_type=AnalyticsRuleSchema,
3837
)
3938
return response
4039

41-
def retrieve(self, *, rule_tag: typing.Union[str, None] = None) -> typing.List[AnalyticsRule]:
40+
def retrieve(
41+
self, *, rule_tag: typing.Union[str, None] = None
42+
) -> typing.List[AnalyticsRuleSchema]:
4243
params: typing.Dict[str, str] = {}
4344
if rule_tag:
4445
params["rule_tag"] = rule_tag
45-
response: typing.List[AnalyticsRule] = self.api_call.get(
46+
response: typing.List[AnalyticsRuleSchema] = self.api_call.get(
4647
AnalyticsRules.resource_path,
4748
params=params if params else None,
4849
as_json=True,
49-
entity_type=typing.List[AnalyticsRule],
50+
entity_type=typing.List[AnalyticsRuleSchema],
5051
)
5152
return response
5253

53-
def upsert(self, rule_name: str, update: AnalyticsRuleUpdate) -> AnalyticsRule:
54-
response: AnalyticsRule = self.api_call.put(
54+
def upsert(
55+
self, rule_name: str, update: AnalyticsRuleUpdate
56+
) -> AnalyticsRuleSchema:
57+
response: AnalyticsRuleSchema = self.api_call.put(
5558
"/".join([AnalyticsRules.resource_path, rule_name]),
5659
body=update,
57-
entity_type=AnalyticsRule,
60+
entity_type=AnalyticsRuleSchema,
5861
)
59-
return response
62+
return response

src/typesense/types/analytics.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class AnalyticsStatus(typing.TypedDict, total=False):
5151

5252
# Rules
5353

54+
5455
class AnalyticsRuleParams(typing.TypedDict, total=False):
5556
destination_collection: typing.NotRequired[str]
5657
limit: typing.NotRequired[int]
@@ -76,7 +77,5 @@ class AnalyticsRuleUpdate(typing.TypedDict, total=False):
7677
params: AnalyticsRuleParams
7778

7879

79-
class AnalyticsRule(AnalyticsRuleCreate, total=False):
80+
class AnalyticsRuleSchema(AnalyticsRuleCreate, total=False):
8081
pass
81-
82-

0 commit comments

Comments
 (0)