Skip to content

Commit d562130

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 e45871d commit d562130

File tree

9 files changed

+57
-26
lines changed

9 files changed

+57
-26
lines changed

src/typesense/analytics_rule_v1.py

Lines changed: 6 additions & 3 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).
@@ -48,7 +53,7 @@ class AnalyticsRuleV1:
4853
rule_id (str): The ID of the analytics rule.
4954
"""
5055

51-
@warn_deprecation(
56+
@warn_deprecation( # type: ignore[misc]
5257
"AnalyticsRuleV1 is deprecated on v30+. Use client.analytics.rules[rule_id] instead.",
5358
flag_name="analytics_rules_v1_deprecation",
5459
)
@@ -107,5 +112,3 @@ def _endpoint_path(self) -> str:
107112
from typesense.analytics_rules_v1 import AnalyticsRulesV1
108113

109114
return "/".join([AnalyticsRulesV1.resource_path, self.rule_id])
110-
111-

src/typesense/analytics_rules_v1.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class AnalyticsRulesV1(object):
6565

6666
resource_path: typing.Final[str] = "/analytics/rules"
6767

68-
@warn_deprecation(
68+
@warn_deprecation( # type: ignore[misc]
6969
"AnalyticsRulesV1 is deprecated on v30+. Use client.analytics instead.",
7070
flag_name="analytics_rules_v1_deprecation",
7171
)
@@ -167,5 +167,3 @@ def retrieve(self) -> RulesRetrieveSchema:
167167
entity_type=RulesRetrieveSchema,
168168
)
169169
return response
170-
171-

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: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
import sys
3030

31+
from typing_extensions import deprecated
32+
3133
from typesense.types.document import DocumentSchema
3234

3335
if sys.version_info >= (3, 11):
@@ -36,8 +38,8 @@
3638
import typing_extensions as typing
3739

3840
from typesense.aliases import Aliases
39-
from typesense.analytics_v1 import AnalyticsV1
4041
from typesense.analytics import Analytics
42+
from typesense.analytics_v1 import AnalyticsV1
4143
from typesense.api_call import ApiCall
4244
from typesense.collection import Collection
4345
from typesense.collections import Collections
@@ -108,7 +110,7 @@ def __init__(self, config_dict: ConfigDict) -> None:
108110
self.multi_search = MultiSearch(self.api_call)
109111
self.keys = Keys(self.api_call)
110112
self.aliases = Aliases(self.api_call)
111-
self.analyticsV1 = AnalyticsV1(self.api_call)
113+
self._analyticsV1 = AnalyticsV1(self.api_call)
112114
self.analytics = Analytics(self.api_call)
113115
self.stemming = Stemming(self.api_call)
114116
self.curation_sets = CurationSets(self.api_call)
@@ -120,6 +122,14 @@ def __init__(self, config_dict: ConfigDict) -> None:
120122
self.conversations_models = ConversationsModels(self.api_call)
121123
self.nl_search_models = NLSearchModels(self.api_call)
122124

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

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: 4 additions & 1 deletion
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.
@@ -39,7 +42,7 @@ class Override:
3942
override_id (str): The ID of the override.
4043
"""
4144

42-
@warn_deprecation(
45+
@warn_deprecation( # type: ignore[misc]
4346
"The override API (collections/{collection}/overrides/{override_id}) is deprecated is removed on v30+. "
4447
"Use curation sets (curation_sets) instead.",
4548
flag_name="overrides_deprecation",

src/typesense/overrides.py

Lines changed: 5 additions & 2 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.
@@ -60,15 +63,15 @@ class Overrides:
6063

6164
resource_path: typing.Final[str] = "overrides"
6265

63-
@warn_deprecation(
66+
@warn_deprecation( # type: ignore[misc]
6467
"Overrides is deprecated on v30+. Use client.curation_sets instead.",
6568
flag_name="overrides_deprecation",
6669
)
6770
def __init__(
6871
self,
6972
api_call: ApiCall,
7073
collection_name: str,
71-
) -> None:
74+
) -> None:
7275
"""
7376
Initialize the Overrides object.
7477

src/typesense/synonym.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Synonym:
3939
synonym_id (str): The ID of the synonym.
4040
"""
4141

42-
@warn_deprecation(
42+
@warn_deprecation( # type: ignore[misc]
4343
"The synonym API (collections/{collection}/synonyms/{synonym_id}) is deprecated is removed on v30+. "
4444
"Use synonym sets (synonym_sets) instead.",
4545
flag_name="synonyms_deprecation",

src/typesense/synonyms.py

Lines changed: 5 additions & 2 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.
@@ -58,12 +61,12 @@ class Synonyms:
5861

5962
resource_path: typing.Final[str] = "synonyms"
6063

61-
@warn_deprecation(
64+
@warn_deprecation( # type: ignore[misc]
6265
"The synonyms API (collections/{collection}/synonyms) is deprecated is removed on v30+. "
6366
"Use synonym sets (synonym_sets) instead.",
6467
flag_name="synonyms_deprecation",
6568
)
66-
def __init__(self, api_call: ApiCall, collection_name: str):
69+
def __init__(self, api_call: ApiCall, collection_name: str) -> None:
6770
"""
6871
Initialize the Synonyms object.
6972

0 commit comments

Comments
 (0)