Skip to content

Commit e86ce26

Browse files
committed
Try caching methods that check property types
1 parent e2aac19 commit e86ce26

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

singer_sdk/helpers/_typing.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def append_type(type_dict: dict, new_type: str) -> dict:
7979
return result
8080

8181

82+
@lru_cache
8283
def is_secret_type(type_dict: dict) -> bool:
8384
"""Return True if JSON Schema type definition appears to be a secret.
8485
@@ -109,6 +110,7 @@ def is_secret_type(type_dict: dict) -> bool:
109110
return False
110111

111112

113+
@lru_cache
112114
def is_object_type(property_schema: dict) -> bool | None:
113115
"""Return true if the JSON Schema type is an object or None if detection fails."""
114116
if "anyOf" not in property_schema and "type" not in property_schema:
@@ -122,6 +124,7 @@ def is_object_type(property_schema: dict) -> bool | None:
122124
)
123125

124126

127+
@lru_cache
125128
def is_uniform_list(property_schema: dict) -> bool | None:
126129
"""Return true if the JSON Schema type is an array with a single schema.
127130
@@ -136,6 +139,7 @@ def is_uniform_list(property_schema: dict) -> bool | None:
136139
)
137140

138141

142+
@lru_cache
139143
def is_datetime_type(type_dict: dict) -> bool:
140144
"""Return True if JSON Schema type definition is a 'date-time' type.
141145
@@ -155,6 +159,7 @@ def is_datetime_type(type_dict: dict) -> bool:
155159
raise ValueError(msg)
156160

157161

162+
@lru_cache
158163
def is_date_or_datetime_type(type_dict: dict) -> bool:
159164
"""Return True if JSON Schema type definition is a 'date'/'date-time' type.
160165
@@ -186,6 +191,7 @@ def is_date_or_datetime_type(type_dict: dict) -> bool:
186191
raise ValueError(msg)
187192

188193

194+
@lru_cache
189195
def get_datelike_property_type(property_schema: dict) -> str | None:
190196
"""Return one of 'date-time', 'time', or 'date' if property is date-like.
191197
@@ -200,6 +206,7 @@ def get_datelike_property_type(property_schema: dict) -> str | None:
200206
return None
201207

202208

209+
@lru_cache
203210
def _is_string_with_format(type_dict: dict[str, t.Any]) -> bool | None:
204211
if "string" in type_dict.get("type", []) and type_dict.get("format") in {
205212
"date-time",
@@ -236,6 +243,7 @@ def handle_invalid_timestamp_in_record(
236243
raise ValueError(msg)
237244

238245

246+
@lru_cache
239247
def is_string_array_type(type_dict: dict) -> bool:
240248
"""Return True if JSON Schema type definition is a string array."""
241249
if not type_dict:
@@ -254,6 +262,7 @@ def is_string_array_type(type_dict: dict) -> bool:
254262
return "array" in type_dict["type"] and bool(is_string_type(type_dict["items"]))
255263

256264

265+
@lru_cache
257266
def is_array_type(type_dict: dict) -> bool:
258267
"""Return True if JSON Schema type is an array."""
259268
if not type_dict:
@@ -272,6 +281,7 @@ def is_array_type(type_dict: dict) -> bool:
272281
return "array" in type_dict["type"]
273282

274283

284+
@lru_cache
275285
def is_boolean_type(property_schema: dict) -> bool | None:
276286
"""Return true if the JSON Schema type is a boolean or None if detection fails."""
277287
if "anyOf" not in property_schema and "type" not in property_schema:
@@ -287,6 +297,7 @@ def is_boolean_type(property_schema: dict) -> bool | None:
287297
return False
288298

289299

300+
@lru_cache
290301
def _is_exclusive_boolean_type(property_schema: dict) -> bool:
291302
if "type" not in property_schema:
292303
return False
@@ -298,6 +309,7 @@ def _is_exclusive_boolean_type(property_schema: dict) -> bool:
298309
)
299310

300311

312+
@lru_cache
301313
def is_integer_type(property_schema: dict) -> bool | None:
302314
"""Return true if the JSON Schema type is an integer or None if detection fails."""
303315
if "anyOf" not in property_schema and "type" not in property_schema:
@@ -313,6 +325,7 @@ def is_integer_type(property_schema: dict) -> bool | None:
313325
return False
314326

315327

328+
@lru_cache
316329
def is_string_type(property_schema: dict) -> bool | None:
317330
"""Return true if the JSON Schema type is a string or None if detection fails."""
318331
if "anyOf" not in property_schema and "type" not in property_schema:
@@ -328,6 +341,7 @@ def is_string_type(property_schema: dict) -> bool | None:
328341
return False
329342

330343

344+
@lru_cache
331345
def is_null_type(property_schema: dict) -> bool | None:
332346
"""Return true if the JSON Schema type is a null or None if detection fails."""
333347
if "anyOf" not in property_schema and "type" not in property_schema:
@@ -343,6 +357,7 @@ def is_null_type(property_schema: dict) -> bool | None:
343357
return False
344358

345359

360+
@lru_cache
346361
def is_number_type(property_schema: dict) -> bool | None:
347362
"""Return true if the JSON Schema type is a number or None if detection fails."""
348363
if "anyOf" not in property_schema and "type" not in property_schema:

0 commit comments

Comments
 (0)