Skip to content

Commit 4123f1f

Browse files
committed
Remove an optimization that's slower than the obvious in 3.12+
1 parent 9cb4020 commit 4123f1f

File tree

1 file changed

+7
-21
lines changed

1 file changed

+7
-21
lines changed

src/async_utils/_paramkey.py

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,9 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
# This used to include CPython code, some minor performance losses have been
16-
# taken to not tightly include upstream code
17-
18-
1915
from __future__ import annotations
2016

21-
from collections.abc import Callable, Hashable
17+
from collections.abc import Hashable
2218

2319
from . import _typings as t
2420

@@ -28,14 +24,14 @@
2824
class _HK:
2925
__slots__ = ("_hashvalue", "_tup")
3026

31-
def __init__(self, tup: Hashable) -> None:
27+
def __init__(self, tup: Hashable, /) -> None:
3228
self._tup = tup
3329
self._hashvalue = hash(tup)
3430

35-
def __hash__(self) -> int:
31+
def __hash__(self, /) -> int:
3632
return self._hashvalue
3733

38-
def __eq__(self, other: object) -> bool:
34+
def __eq__(self, other: object, /) -> bool:
3935
if not isinstance(other, _HK):
4036
return False
4137
return self._tup == other._tup
@@ -44,22 +40,12 @@ def __eq__(self, other: object) -> bool:
4440
_marker: tuple[object] = (object(),)
4541

4642

47-
def _make_key(
48-
args: tuple[t.Any, ...],
49-
kwds: dict[t.Any, t.Any],
50-
/,
51-
*,
52-
_typ: Callable[[object], type] = type,
53-
_fast_types: set[type] = {int, str}, # noqa: B006 # pyright: ignore[reportCallInDefaultInitializer]
54-
) -> Hashable:
43+
def make_key(args: tuple[t.Any, ...], kwds: dict[t.Any, t.Any], /) -> Hashable:
5544
key: tuple[t.Any, ...] = args
5645
if kwds:
5746
key += _marker
5847
for item in kwds.items():
5948
key += item
60-
elif len(key) == 1 and _typ(key[0]) in _fast_types:
61-
return key[0]
49+
elif len(key) == 1 and type(a := key[0]) in {int, str}:
50+
return a
6251
return _HK(key)
63-
64-
65-
make_key: Callable[[tuple[t.Any, ...], dict[t.Any, t.Any]], Hashable] = _make_key

0 commit comments

Comments
 (0)