-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLenOverloads.py
More file actions
36 lines (21 loc) · 1.02 KB
/
Copy pathLenOverloads.py
File metadata and controls
36 lines (21 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
@namespace("Promethium")
from collections import Counter, OrderedDict, ChainMap, Deque, DefaultDict
# The built-in `len()` only has overloads for PromethiumBaseLibrary's own
# List/Dictionary/Set/str (declared in Builtins.py, in this same "Promethium"
# namespace). Overload resolution combines same-named functions across
# assemblies within one open namespace, so declaring more `len` overloads
# here — in "Promethium", not "collections" — extends that same overload
# set: `len(counts)` now works directly for every class in this library,
# instead of requiring `.__len__()`.
def len[T](value: Counter[T]) -> int:
return value.__len__()
def len[Key, Value](value: OrderedDict[Key, Value]) -> int:
return value.__len__()
def len[Key, Value](value: ChainMap[Key, Value]) -> int:
return value.__len__()
def len[T](value: Deque[T]) -> int:
return value.__len__()
def len[Key, Value](value: DefaultDict[Key, Value]) -> int:
return value.__len__()
def len(value: PyByteArray) -> int:
return value.__len__()