python-intl 0.6.0__tar.gz → 0.7.1__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: python-intl
3
- Version: 0.6.0
3
+ Version: 0.7.1
4
4
  Summary: Python implementation of the Intl JavaScript API
5
5
  Author: David Danier
6
6
  Author-email: David Danier <david.danier@gmail.com>
@@ -87,6 +87,20 @@ formatter.format_range(datetime, datetime_till)
87
87
 
88
88
  ### `Intl.Collator`
89
89
 
90
+ #### Example usage
91
+
92
+ ```python
93
+ import python_intl as Intl
94
+
95
+ collator = Intl.Collator("de-DE", {"numeric": True})
96
+ collator.compare("10", "9")
97
+ # Result = 1, which means 9 comes before 10
98
+
99
+ # You can also use sorted, although this is not available in JavaScript
100
+ collator.sorted(["10", "9"])
101
+ # Result = ['9', '10']
102
+ ```
103
+
90
104
  #### Compatibility
91
105
 
92
106
  | Method | Status | Python name |
@@ -95,6 +109,12 @@ formatter.format_range(datetime, datetime_till)
95
109
 
96
110
  **Note:** Not all options are currently supported.
97
111
 
112
+ #### Additional methods
113
+
114
+ * `Collator.sorted`: Somewhat like `sorted`, but uses the collator for comparison. If you want
115
+ to sort complex datastructures you can provide a `key` parameter (like with `sorted`) to
116
+ get a comparable string value (for example by returning an attribute).
117
+
98
118
  ## Installation
99
119
 
100
120
  Be sure to be able to install `PyICU`, see the installation docs there:
@@ -74,6 +74,20 @@ formatter.format_range(datetime, datetime_till)
74
74
 
75
75
  ### `Intl.Collator`
76
76
 
77
+ #### Example usage
78
+
79
+ ```python
80
+ import python_intl as Intl
81
+
82
+ collator = Intl.Collator("de-DE", {"numeric": True})
83
+ collator.compare("10", "9")
84
+ # Result = 1, which means 9 comes before 10
85
+
86
+ # You can also use sorted, although this is not available in JavaScript
87
+ collator.sorted(["10", "9"])
88
+ # Result = ['9', '10']
89
+ ```
90
+
77
91
  #### Compatibility
78
92
 
79
93
  | Method | Status | Python name |
@@ -82,6 +96,12 @@ formatter.format_range(datetime, datetime_till)
82
96
 
83
97
  **Note:** Not all options are currently supported.
84
98
 
99
+ #### Additional methods
100
+
101
+ * `Collator.sorted`: Somewhat like `sorted`, but uses the collator for comparison. If you want
102
+ to sort complex datastructures you can provide a `key` parameter (like with `sorted`) to
103
+ get a comparable string value (for example by returning an attribute).
104
+
85
105
  ## Installation
86
106
 
87
107
  Be sure to be able to install `PyICU`, see the installation docs there:
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "python-intl"
3
- version = "0.6.0"
3
+ version = "0.7.1"
4
4
  description = "Python implementation of the Intl JavaScript API"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "python-intl"
3
- version = "0.6.0"
3
+ version = "0.7.1"
4
4
  description = "Python implementation of the Intl JavaScript API"
5
5
  readme = "README.md"
6
6
  authors = [
@@ -1,8 +1,10 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import dataclasses
4
+ import functools
5
+ from collections.abc import Callable, Iterable
4
6
  from functools import cached_property
5
- from typing import TYPE_CHECKING, Literal
7
+ from typing import TYPE_CHECKING, Literal, overload
6
8
 
7
9
  import icu # type: ignore[import-untyped]
8
10
 
@@ -124,3 +126,17 @@ class Collator:
124
126
 
125
127
  def compare(self, string_a: str, string_b: str) -> ComparisonResultT:
126
128
  return _COLLATOR_RESULT_TO_RESULT[self._icu_collator.compare(string_a, string_b)]
129
+
130
+ @overload
131
+ def sorted(self, items: Iterable[str], /, key: None = None) -> Iterable[str]: ...
132
+ @overload
133
+ def sorted[T](self, items: Iterable[T], /, key: Callable[[T], str]) -> Iterable[T]: ...
134
+ def sorted(self, items, /, key = None):
135
+ return sorted(
136
+ items,
137
+ key=functools.cmp_to_key(
138
+ (lambda a, b: self.compare(key(a), key(b)))
139
+ if key
140
+ else self.compare,
141
+ ),
142
+ )
File without changes