temparse 0.0.4__tar.gz → 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: temparse
3
- Version: 0.0.4
3
+ Version: 1.0.0
4
4
  Summary: temparse is template + parse
5
5
  Author: jiang-zhexin
6
6
  Author-email: jiang-zhexin <162887873+jiang-zhexin@users.noreply.github.com>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "temparse"
3
- version = "0.0.4"
3
+ version = "1.0.0"
4
4
  description = "temparse is template + parse"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.14"
@@ -23,9 +23,9 @@ homepage = "https://github.com/jiang-zhexin/temparse"
23
23
 
24
24
  [dependency-groups]
25
25
  dev = [
26
- "pytest>=9.0.3",
27
- "ruff>=0.15.15",
28
- "ty>=0.0.43",
26
+ "pytest>=9.1.1",
27
+ "ruff>=0.15.22",
28
+ "ty>=0.0.61",
29
29
  ]
30
30
 
31
31
  [build-system]
@@ -1,17 +1,15 @@
1
1
  import datetime
2
2
  import functools
3
3
  import json
4
- import logging
5
4
  import re
6
5
  from collections.abc import Callable
7
6
  from string.templatelib import Interpolation, Template
8
- from typing import Any, get_origin, is_typeddict
7
+ from typing import Any, cast, final, get_origin, is_typeddict
9
8
 
10
9
  __all__ = ["Conversion", "FormatConversion", "Parser", "parse"]
11
10
 
12
- log = logging.getLogger(__name__)
13
-
14
11
 
12
+ @final
15
13
  class Parser[*T]:
16
14
  """
17
15
  A compiled template parser that can be reused to parse multiple strings.
@@ -34,8 +32,6 @@ class Parser[*T]:
34
32
  re.escape(item) if isinstance(item, str) else r"(.+?)" for item in template
35
33
  )
36
34
 
37
- log.debug(f"match expression: {self._expression!r}")
38
-
39
35
  @functools.cached_property
40
36
  def _match_re(self) -> re.Pattern[str]:
41
37
  return re.compile(self._expression, self._flags)
@@ -45,12 +41,18 @@ class Parser[*T]:
45
41
  if m is None:
46
42
  raise ValueError(f"invalid format: {s!r}")
47
43
 
48
- return tuple(
49
- _convert(text, interpolation)
50
- for text, interpolation in zip(m.groups(), self._template.interpolations)
44
+ return cast(
45
+ tuple[*T],
46
+ tuple(
47
+ _convert(text, interpolation)
48
+ for text, interpolation in zip(
49
+ m.groups(), self._template.interpolations
50
+ )
51
+ ),
51
52
  )
52
53
 
53
54
 
55
+ @final
54
56
  class parse[*T]:
55
57
  """
56
58
  Parse string by template.
@@ -74,9 +76,10 @@ class parse[*T]:
74
76
  return Parser(t).parse(s)
75
77
  ```
76
78
  """
77
- return Parser(t, flags).parse(s)
79
+ return Parser[*T](t, flags).parse(s)
78
80
 
79
81
 
82
+ @final
80
83
  class Conversion[T]:
81
84
  """
82
85
  Convert the string to your object.
@@ -104,6 +107,7 @@ class Conversion[T]:
104
107
  return self._convert(s)
105
108
 
106
109
 
110
+ @final
107
111
  class FormatConversion[T]:
108
112
  """
109
113
  Convert the string to your object with format.
File without changes
File without changes