Skip to content

Commit 65ac330

Browse files
committed
feat: add typing deprecation decorators to deprecated apis
- add @deprecated decorator to analytics_rule_v1, analytics_v1 classes - add @deprecated decorator to override, overrides, synonyms classes - convert analyticsV1 to private attribute with deprecated property - convert overrides and synonyms to private attributes with deprecated properties - remove manual deprecation warning code from analytics_v1 - enable static type checker warnings for deprecated apis
1 parent 1d4d1a5 commit 65ac330

File tree

7 files changed

+50
-14
lines changed

7 files changed

+50
-14
lines changed

src/typesense/analytics_rule_v1.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
else:
2828
import typing_extensions as typing
2929

30+
from typing_extensions import deprecated
31+
3032
from typesense.api_call import ApiCall
3133
from typesense.logger import warn_deprecation
3234
from typesense.types.analytics_rule_v1 import (
@@ -36,6 +38,9 @@
3638
)
3739

3840

41+
@deprecated(
42+
"AnalyticsRuleV1 is deprecated on v30+. Use client.analytics.rules[rule_id] instead."
43+
)
3944
class AnalyticsRuleV1:
4045
"""
4146
Class for managing individual analytics rules in Typesense (V1).

src/typesense/analytics_v1.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
versions through the use of the typing_extensions library.
1818
"""
1919

20+
from typing_extensions import deprecated
21+
2022
from typesense.analytics_rules_v1 import AnalyticsRulesV1
2123
from typesense.api_call import ApiCall
22-
from typesense.logger import logger
23-
24-
_analytics_v1_deprecation_warned = False
2524

2625

26+
@deprecated("AnalyticsV1 is deprecated on v30+. Use client.analytics instead.")
2727
class AnalyticsV1(object):
2828
"""
2929
Class for managing analytics in Typesense (V1).
@@ -46,13 +46,6 @@ def __init__(self, api_call: ApiCall) -> None:
4646

4747
@property
4848
def rules(self) -> AnalyticsRulesV1:
49-
global _analytics_v1_deprecation_warned
50-
if not _analytics_v1_deprecation_warned:
51-
logger.warning(
52-
"AnalyticsV1 is deprecated and will be removed in a future release. "
53-
"Use client.analytics instead."
54-
)
55-
_analytics_v1_deprecation_warned = True
5649
return self._rules
5750

5851

src/typesense/client.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
"""
2828

2929
import sys
30+
from inspect import stack
31+
32+
from typing_extensions import deprecated
3033

3134
from typesense.types.document import DocumentSchema
3235

@@ -36,8 +39,8 @@
3639
import typing_extensions as typing
3740

3841
from typesense.aliases import Aliases
39-
from typesense.analytics_v1 import AnalyticsV1
4042
from typesense.analytics import Analytics
43+
from typesense.analytics_v1 import AnalyticsV1
4144
from typesense.api_call import ApiCall
4245
from typesense.collection import Collection
4346
from typesense.collections import Collections
@@ -108,7 +111,7 @@ def __init__(self, config_dict: ConfigDict) -> None:
108111
self.multi_search = MultiSearch(self.api_call)
109112
self.keys = Keys(self.api_call)
110113
self.aliases = Aliases(self.api_call)
111-
self.analyticsV1 = AnalyticsV1(self.api_call)
114+
self._analyticsV1 = AnalyticsV1(self.api_call)
112115
self.analytics = Analytics(self.api_call)
113116
self.stemming = Stemming(self.api_call)
114117
self.curation_sets = CurationSets(self.api_call)
@@ -120,6 +123,14 @@ def __init__(self, config_dict: ConfigDict) -> None:
120123
self.conversations_models = ConversationsModels(self.api_call)
121124
self.nl_search_models = NLSearchModels(self.api_call)
122125

126+
@property
127+
@deprecated(
128+
"AnalyticsV1 is deprecated on v30+. Use client.analytics instead.",
129+
category=None,
130+
)
131+
def analyticsV1(self) -> AnalyticsV1:
132+
return self._analyticsV1
133+
123134
def typed_collection(
124135
self,
125136
*,

src/typesense/collection.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
import sys
2222

23+
from typing_extensions import deprecated
24+
2325
from typesense.types.collection import CollectionSchema, CollectionUpdateSchema
2426

2527
if sys.version_info >= (3, 11):
@@ -63,8 +65,24 @@ def __init__(self, api_call: ApiCall, name: str):
6365
self.name = name
6466
self.api_call = api_call
6567
self.documents: Documents[TDoc] = Documents(api_call, name)
66-
self.overrides = Overrides(api_call, name)
67-
self.synonyms = Synonyms(api_call, name)
68+
self._overrides = Overrides(api_call, name)
69+
self._synonyms = Synonyms(api_call, name)
70+
71+
@property
72+
@deprecated(
73+
"Synonyms is deprecated on v30+. Use client.synonym_sets instead.",
74+
category=None,
75+
)
76+
def synonyms(self) -> Synonyms:
77+
return self._synonyms
78+
79+
@property
80+
@deprecated(
81+
"Overrides is deprecated on v30+. Use client.curation_sets instead.",
82+
category=None,
83+
)
84+
def overrides(self) -> Overrides:
85+
return self._overrides
6886

6987
def retrieve(self) -> CollectionSchema:
7088
"""

src/typesense/override.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@
2121
versions through the use of the typing_extensions library.
2222
"""
2323

24+
from typing_extensions import deprecated
25+
2426
from typesense.api_call import ApiCall
2527
from typesense.logger import warn_deprecation
2628
from typesense.types.override import OverrideDeleteSchema, OverrideSchema
2729

2830

31+
@deprecated("Override is deprecated on v30+. Use client.curation_sets instead.")
2932
class Override:
3033
"""
3134
Class for managing individual overrides in a Typesense collection.

src/typesense/overrides.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
import sys
3131

32+
from typing_extensions import deprecated
33+
3234
from typesense.api_call import ApiCall
3335
from typesense.logger import warn_deprecation
3436
from typesense.override import Override
@@ -44,6 +46,7 @@
4446
import typing_extensions as typing
4547

4648

49+
@deprecated("Overrides is deprecated on v30+. Use client.curation_sets instead.")
4750
class Overrides:
4851
"""
4952
Class for managing overrides in a Typesense collection.

src/typesense/synonyms.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
import sys
2929

30+
from typing_extensions import deprecated
31+
3032
from typesense.api_call import ApiCall
3133
from typesense.logger import warn_deprecation
3234
from typesense.synonym import Synonym
@@ -42,6 +44,7 @@
4244
import typing_extensions as typing
4345

4446

47+
@deprecated("Synonyms is deprecated on v30+. Use client.synonym_sets instead.")
4548
class Synonyms:
4649
"""
4750
Class for managing synonyms in a Typesense collection.

0 commit comments

Comments
 (0)