Skip to content

Commit ade6619

Browse files
authored
Fix memleak by dropping lru cache (#227)
1 parent 21f51a5 commit ade6619

File tree

2 files changed

+11
-26
lines changed

2 files changed

+11
-26
lines changed

tomlkit/items.py

+5-12
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,6 @@ class StringType(Enum):
258258
# Multi Line Literal
259259
MLL = "'''"
260260

261-
def __init__(self, value):
262-
self.is_basic = lru_cache(maxsize=None)(self._is_basic)
263-
self.is_literal = lru_cache(maxsize=None)(self._is_literal)
264-
self.is_singleline = lru_cache(maxsize=None)(self._is_singleline)
265-
self.is_multiline = lru_cache(maxsize=None)(self._is_multiline)
266-
self.toggle = lru_cache(maxsize=None)(self._toggle)
267-
268261
@classmethod
269262
def select(cls, literal=False, multiline=False) -> "StringType":
270263
return {
@@ -302,19 +295,19 @@ def invalid_sequences(self) -> Collection[str]:
302295
def unit(self) -> str:
303296
return self.value[0]
304297

305-
def _is_basic(self) -> bool:
298+
def is_basic(self) -> bool:
306299
return self in {StringType.SLB, StringType.MLB}
307300

308-
def _is_literal(self) -> bool:
301+
def is_literal(self) -> bool:
309302
return self in {StringType.SLL, StringType.MLL}
310303

311-
def _is_singleline(self) -> bool:
304+
def is_singleline(self) -> bool:
312305
return self in {StringType.SLB, StringType.SLL}
313306

314-
def _is_multiline(self) -> bool:
307+
def is_multiline(self) -> bool:
315308
return self in {StringType.MLB, StringType.MLL}
316309

317-
def _toggle(self) -> "StringType":
310+
def toggle(self) -> "StringType":
318311
return {
319312
StringType.SLB: StringType.MLB,
320313
StringType.MLB: StringType.SLB,

tomlkit/toml_char.py

+6-14
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
import string
22

3-
from functools import lru_cache
4-
53

64
class TOMLChar(str):
75
def __init__(self, c):
8-
self.is_bare_key_char = lru_cache(maxsize=None)(self._is_bare_key_char)
9-
self.is_kv_sep = lru_cache(maxsize=None)(self._is_kv_sep)
10-
self.is_int_float_char = lru_cache(maxsize=None)(self._is_int_float_char)
11-
self.is_ws = lru_cache(maxsize=None)(self._is_ws)
12-
self.is_nl = lru_cache(maxsize=None)(self._is_nl)
13-
self.is_spaces = lru_cache(maxsize=None)(self._is_spaces)
146
super().__init__()
157

168
if len(self) > 1:
@@ -23,37 +15,37 @@ def __init__(self, c):
2315
NL = "\n\r"
2416
WS = SPACES + NL
2517

26-
def _is_bare_key_char(self) -> bool:
18+
def is_bare_key_char(self) -> bool:
2719
"""
2820
Whether the character is a valid bare key name or not.
2921
"""
3022
return self in self.BARE
3123

32-
def _is_kv_sep(self) -> bool:
24+
def is_kv_sep(self) -> bool:
3325
"""
3426
Whether the character is a valid key/value separator or not.
3527
"""
3628
return self in self.KV
3729

38-
def _is_int_float_char(self) -> bool:
30+
def is_int_float_char(self) -> bool:
3931
"""
4032
Whether the character if a valid integer or float value character or not.
4133
"""
4234
return self in self.NUMBER
4335

44-
def _is_ws(self) -> bool:
36+
def is_ws(self) -> bool:
4537
"""
4638
Whether the character is a whitespace character or not.
4739
"""
4840
return self in self.WS
4941

50-
def _is_nl(self) -> bool:
42+
def is_nl(self) -> bool:
5143
"""
5244
Whether the character is a new line character or not.
5345
"""
5446
return self in self.NL
5547

56-
def _is_spaces(self) -> bool:
48+
def is_spaces(self) -> bool:
5749
"""
5850
Whether the character is a space or not
5951
"""

0 commit comments

Comments
 (0)