Accept suggestions from new toolchain · rec/abbrev@8585ec0

Original file line numberDiff line numberDiff line change

@@ -62,8 +62,10 @@

6262

assert abbrev(d, 't', unique=False) == (200, 300)

6363

"""

6464
65-

from typing import Any, Mapping, Optional, Sequence, Union

6665

import functools

66+

from collections.abc import Mapping, Sequence

67+

from typing import Any

68+
6769

import xmod

6870
6971

__all__ = 'abbrev', 'NONE'

@@ -73,8 +75,8 @@

7375
7476

@xmod.xmod

7577

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,

7880

default: Any = NONE,

7981

multi: bool = False,

8082

unique: bool = True,

@@ -112,16 +114,14 @@ def abbrev(

112114

abbrev, abbrevs, default=default, multi=multi, unique=unique

113115

)

114116
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}

118118

r = abbrevs.get(key, NONE)

119119

if r is not NONE:

120120

return (r,) if multi else r

121121
122122

kv = [(k, v) for k, v in abbrevs.items() if k.startswith(key)]

123123

if kv:

124-

keys, values = zip(*kv)

124+

keys, values = zip(*kv, strict=False)

125125
126126

elif multi:

127127

return []