|
62 | 62 | assert abbrev(d, 't', unique=False) == (200, 300) |
63 | 63 | """ |
64 | 64 |
|
65 | | -from typing import Any, Mapping, Optional, Sequence, Union |
66 | 65 | import functools |
| 66 | +from collections.abc import Mapping, Sequence |
| 67 | +from typing import Any |
| 68 | + |
67 | 69 | import xmod |
68 | 70 |
|
69 | 71 | __all__ = 'abbrev', 'NONE' |
|
73 | 75 |
|
74 | 76 | @xmod.xmod |
75 | 77 | def abbrev( |
76 | | - abbrevs: Union[ Mapping[str, Any], Sequence[str] ], |
77 | | - key: Optional[str] = None, |
| 78 | + abbrevs: Mapping[str, Any] | Sequence[str], |
| 79 | + key: str | None = None, |
78 | 80 | default: Any = NONE, |
79 | 81 | multi: bool = False, |
80 | 82 | unique: bool = True, |
@@ -112,16 +114,14 @@ def abbrev( |
112 | 114 | abbrev, abbrevs, default=default, multi=multi, unique=unique |
113 | 115 | ) |
114 | 116 |
|
115 | | - if not isinstance(abbrevs, dict): |
116 | | - abbrevs = {i: i for i in abbrevs} |
117 | | - |
| 117 | + abbrevs = abbrevs if isinstance(abbrevs, dict) else {i: i for i in abbrevs} |
118 | 118 | r = abbrevs.get(key, NONE) |
119 | 119 | if r is not NONE: |
120 | 120 | return (r,) if multi else r |
121 | 121 |
|
122 | 122 | kv = [(k, v) for k, v in abbrevs.items() if k.startswith(key)] |
123 | 123 | if kv: |
124 | | - keys, values = zip(*kv) |
| 124 | + keys, values = zip(*kv, strict=False) |
125 | 125 |
|
126 | 126 | elif multi: |
127 | 127 | return [] |
|
0 commit comments