Skip to content

Commit a6c2d70

Browse files
committed
micro opt in make_key
1 parent 38a59c5 commit a6c2d70

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/async_utils/_paramkey.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from __future__ import annotations
2020

21-
from collections.abc import Hashable
21+
from collections.abc import Callable, Hashable
2222

2323
from . import _typings as t
2424

@@ -44,12 +44,17 @@ def __eq__(self, other: object) -> bool:
4444
_marker: tuple[object] = (object(),)
4545

4646

47-
def make_key(args: tuple[t.Any, ...], kwds: dict[t.Any, t.Any]) -> Hashable:
47+
def make_key(
48+
args: tuple[t.Any, ...],
49+
kwds: dict[t.Any, t.Any],
50+
_typ: Callable[[object], type] = type,
51+
_fast_types: set[type] = {int, str}, # noqa: B006
52+
) -> Hashable:
4853
key: tuple[t.Any, ...] = args
4954
if kwds:
5055
key += _marker
5156
for item in kwds.items():
5257
key += item
53-
elif len(key) == 1 and type(key[0]) in {int, str}:
58+
elif len(key) == 1 and _typ(key[0]) in _fast_types:
5459
return key[0]
5560
return _HK(key)

0 commit comments

Comments
 (0)