1818 ClassVar ,
1919 Generic ,
2020 NoReturn ,
21- Optional ,
2221 TypeVar ,
23- Union ,
2422 cast ,
2523 overload ,
2624)
@@ -37,7 +35,7 @@ class istr(str):
3735 """Case insensitive str."""
3836
3937 __is_istr__ = True
40- __istr_identity__ : Optional [ str ] = None
38+ __istr_identity__ : str | None = None
4139
4240
4341_V = TypeVar ("_V" )
@@ -109,9 +107,7 @@ def __repr__(self) -> str:
109107 body = ", " .join (lst )
110108 return f"<{ self .__class__ .__name__ } ({ body } )>"
111109
112- def _parse_item (
113- self , arg : Union [tuple [str , _V ], _T ]
114- ) -> Optional [tuple [int , str , str , _V ]]:
110+ def _parse_item (self , arg : tuple [str , _V ] | _T ) -> tuple [int , str , str , _V ] | None :
115111 if not isinstance (arg , tuple ):
116112 return None
117113 if len (arg ) != 2 :
@@ -167,14 +163,14 @@ def __rand__(self, other: Iterable[_T]) -> set[_T]:
167163 break
168164 return ret
169165
170- def __or__ (self , other : Iterable [_T ]) -> set [Union [ tuple [str , _V ], _T ] ]:
171- ret : set [Union [ tuple [str , _V ], _T ] ] = set (self )
166+ def __or__ (self , other : Iterable [_T ]) -> set [tuple [str , _V ] | _T ]:
167+ ret : set [tuple [str , _V ] | _T ] = set (self )
172168 try :
173169 it = iter (other )
174170 except TypeError :
175171 return NotImplemented
176172 for arg in it :
177- item : Optional [ tuple [int , str , str , _V ]] = self ._parse_item (arg )
173+ item : tuple [int , str , str , _V ] | None = self ._parse_item (arg )
178174 if item is None :
179175 ret .add (arg )
180176 continue
@@ -186,9 +182,9 @@ def __or__(self, other: Iterable[_T]) -> set[Union[tuple[str, _V], _T]]:
186182 ret .add (arg )
187183 return ret
188184
189- def __ror__ (self , other : Iterable [_T ]) -> set [Union [ tuple [str , _V ], _T ] ]:
185+ def __ror__ (self , other : Iterable [_T ]) -> set [tuple [str , _V ] | _T ]:
190186 try :
191- ret : set [Union [ tuple [str , _V ], _T ] ] = set (other )
187+ ret : set [tuple [str , _V ] | _T ] = set (other )
192188 except TypeError :
193189 return NotImplemented
194190 tmp = self ._tmp_set (ret )
@@ -198,8 +194,8 @@ def __ror__(self, other: Iterable[_T]) -> set[Union[tuple[str, _V], _T]]:
198194 ret .add ((e .key , e .value ))
199195 return ret
200196
201- def __sub__ (self , other : Iterable [_T ]) -> set [Union [ tuple [str , _V ], _T ] ]:
202- ret : set [Union [ tuple [str , _V ], _T ] ] = set ()
197+ def __sub__ (self , other : Iterable [_T ]) -> set [tuple [str , _V ] | _T ]:
198+ ret : set [tuple [str , _V ] | _T ] = set ()
203199 try :
204200 it = iter (other )
205201 except TypeError :
@@ -232,12 +228,12 @@ def __rsub__(self, other: Iterable[_T]) -> set[_T]:
232228 ret .add (arg )
233229 return ret
234230
235- def __xor__ (self , other : Iterable [_T ]) -> set [Union [ tuple [str , _V ], _T ] ]:
231+ def __xor__ (self , other : Iterable [_T ]) -> set [tuple [str , _V ] | _T ]:
236232 try :
237233 rgt = set (other )
238234 except TypeError :
239235 return NotImplemented
240- ret : set [Union [ tuple [str , _V ], _T ] ] = self - rgt
236+ ret : set [tuple [str , _V ] | _T ] = self - rgt
241237 ret |= rgt - self
242238 return ret
243239
@@ -338,8 +334,8 @@ def __rand__(self, other: Iterable[_T]) -> set[_T]:
338334 ret .add (key )
339335 return cast (set [_T ], ret )
340336
341- def __or__ (self , other : Iterable [_T ]) -> set [Union [ str , _T ] ]:
342- ret : set [Union [ str , _T ] ] = set (self )
337+ def __or__ (self , other : Iterable [_T ]) -> set [str | _T ]:
338+ ret : set [str | _T ] = set (self )
343339 try :
344340 it = iter (other )
345341 except TypeError :
@@ -352,9 +348,9 @@ def __or__(self, other: Iterable[_T]) -> set[Union[str, _T]]:
352348 ret .add (key )
353349 return ret
354350
355- def __ror__ (self , other : Iterable [_T ]) -> set [Union [ str , _T ] ]:
351+ def __ror__ (self , other : Iterable [_T ]) -> set [str | _T ]:
356352 try :
357- ret : set [Union [ str , _T ] ] = set (other )
353+ ret : set [str | _T ] = set (other )
358354 except TypeError :
359355 return NotImplemented
360356
@@ -399,12 +395,12 @@ def __rsub__(self, other: Iterable[_T]) -> set[_T]:
399395 ret .discard (key ) # type: ignore[arg-type]
400396 return ret
401397
402- def __xor__ (self , other : Iterable [_T ]) -> set [Union [ str , _T ] ]:
398+ def __xor__ (self , other : Iterable [_T ]) -> set [str | _T ]:
403399 try :
404400 rgt = set (other )
405401 except TypeError :
406402 return NotImplemented
407- ret : set [Union [ str , _T ] ] = self - rgt # type: ignore[assignment]
403+ ret : set [str | _T ] = self - rgt # type: ignore[assignment]
408404 ret |= rgt - self
409405 return ret
410406
@@ -482,7 +478,7 @@ class _HtKeys(Generic[_V]): # type: ignore[misc]
482478 usable : int
483479
484480 indices : array # type: ignore[type-arg] # TODO(PY312): array[int]
485- entries : list [Optional [ _Entry [_V ]] ]
481+ entries : list [_Entry [_V ] | None ]
486482
487483 @functools .cached_property
488484 def nslots (self ) -> int :
@@ -502,7 +498,7 @@ def __sizeof__(self) -> int:
502498 )
503499
504500 @classmethod
505- def new (cls , log2_size : int , entries : list [Optional [ _Entry [_V ]] ]) -> Self :
501+ def new (cls , log2_size : int , entries : list [_Entry [_V ] | None ]) -> Self :
506502 size = 1 << log2_size
507503 usable = (size << 1 ) // 3
508504 if log2_size < 10 :
@@ -649,10 +645,8 @@ def _from_md(self, md: "MultiDict[_V]") -> None:
649645 @overload
650646 def getall (self , key : str ) -> list [_V ]: ...
651647 @overload
652- def getall (self , key : str , default : _T ) -> Union [list [_V ], _T ]: ...
653- def getall (
654- self , key : str , default : Union [_T , _SENTINEL ] = sentinel
655- ) -> Union [list [_V ], _T ]:
648+ def getall (self , key : str , default : _T ) -> list [_V ] | _T : ...
649+ def getall (self , key : str , default : _T | _SENTINEL = sentinel ) -> list [_V ] | _T :
656650 """Return a list of all values matching the key."""
657651 identity = self ._identity (key )
658652 hash_ = hash (identity )
@@ -676,10 +670,8 @@ def getall(
676670 @overload
677671 def getone (self , key : str ) -> _V : ...
678672 @overload
679- def getone (self , key : str , default : _T ) -> Union [_V , _T ]: ...
680- def getone (
681- self , key : str , default : Union [_T , _SENTINEL ] = sentinel
682- ) -> Union [_V , _T ]:
673+ def getone (self , key : str , default : _T ) -> _V | _T : ...
674+ def getone (self , key : str , default : _T | _SENTINEL = sentinel ) -> _V | _T :
683675 """Get first value matching the key.
684676
685677 Raises KeyError if the key is not found and no default is provided.
@@ -699,10 +691,10 @@ def __getitem__(self, key: str) -> _V:
699691 return self .getone (key )
700692
701693 @overload
702- def get (self , key : str , / ) -> Union [ _V , None ] : ...
694+ def get (self , key : str , / ) -> _V | None : ...
703695 @overload
704- def get (self , key : str , / , default : _T ) -> Union [ _V , _T ] : ...
705- def get (self , key : str , default : Union [ _T , None ] = None ) -> Union [ _V , _T , None ] :
696+ def get (self , key : str , / , default : _T ) -> _V | _T : ...
697+ def get (self , key : str , default : _T | None = None ) -> _V | _T | None :
706698 """Get first value matching the key.
707699
708700 If the key is not found, returns the default (or None if no default is provided)
@@ -799,7 +791,7 @@ def _parse_args(
799791 self ,
800792 arg : MDArg [_V ],
801793 kwargs : Mapping [str , _V ],
802- ) -> Iterator [Union [ int , _Entry [_V ] ]]:
794+ ) -> Iterator [int | _Entry [_V ]]:
803795 identity_func = self ._identity
804796 if arg :
805797 if isinstance (arg , MultiDictProxy ):
@@ -905,11 +897,11 @@ def __delitem__(self, key: str) -> None:
905897
906898 @overload
907899 def setdefault (
908- self : "MultiDict[Union[_T, None] ]" , key : str , default : None = None
909- ) -> Union [ _T , None ] : ...
900+ self : "MultiDict[_T | None]" , key : str , default : None = None
901+ ) -> _T | None : ...
910902 @overload
911903 def setdefault (self , key : str , default : _V ) -> _V : ...
912- def setdefault (self , key : str , default : Union [ _V , None ] = None ) -> Union [ _V , None ] : # type: ignore[misc]
904+ def setdefault (self , key : str , default : _V | None = None ) -> _V | None : # type: ignore[misc]
913905 """Return value for key, set value to default if key is not present."""
914906 identity = self ._identity (key )
915907 hash_ = hash (identity )
@@ -922,10 +914,8 @@ def setdefault(self, key: str, default: Union[_V, None] = None) -> Union[_V, Non
922914 @overload
923915 def popone (self , key : str ) -> _V : ...
924916 @overload
925- def popone (self , key : str , default : _T ) -> Union [_V , _T ]: ...
926- def popone (
927- self , key : str , default : Union [_T , _SENTINEL ] = sentinel
928- ) -> Union [_V , _T ]:
917+ def popone (self , key : str , default : _T ) -> _V | _T : ...
918+ def popone (self , key : str , default : _T | _SENTINEL = sentinel ) -> _V | _T :
929919 """Remove specified key and return the corresponding value.
930920
931921 If key is not found, d is returned if given, otherwise
@@ -952,10 +942,8 @@ def popone(
952942 @overload
953943 def popall (self , key : str ) -> list [_V ]: ...
954944 @overload
955- def popall (self , key : str , default : _T ) -> Union [list [_V ], _T ]: ...
956- def popall (
957- self , key : str , default : Union [_T , _SENTINEL ] = sentinel
958- ) -> Union [list [_V ], _T ]:
945+ def popall (self , key : str , default : _T ) -> list [_V ] | _T : ...
946+ def popall (self , key : str , default : _T | _SENTINEL = sentinel ) -> list [_V ] | _T :
959947 """Remove all occurrences of key and return the list of corresponding
960948 values.
961949
@@ -1139,7 +1127,7 @@ class MultiDictProxy(_CSMixin, MultiMapping[_V]):
11391127
11401128 _md : MultiDict [_V ]
11411129
1142- def __init__ (self , arg : Union [ MultiDict [_V ], " MultiDictProxy[_V]"] ):
1130+ def __init__ (self , arg : " MultiDict[_V] | MultiDictProxy[_V]" ):
11431131 if not isinstance (arg , (MultiDict , MultiDictProxy )):
11441132 raise TypeError (
11451133 f"ctor requires MultiDict or MultiDictProxy instance, not { type (arg )} "
@@ -1155,10 +1143,8 @@ def __reduce__(self) -> NoReturn:
11551143 @overload
11561144 def getall (self , key : str ) -> list [_V ]: ...
11571145 @overload
1158- def getall (self , key : str , default : _T ) -> Union [list [_V ], _T ]: ...
1159- def getall (
1160- self , key : str , default : Union [_T , _SENTINEL ] = sentinel
1161- ) -> Union [list [_V ], _T ]:
1146+ def getall (self , key : str , default : _T ) -> list [_V ] | _T : ...
1147+ def getall (self , key : str , default : _T | _SENTINEL = sentinel ) -> list [_V ] | _T :
11621148 """Return a list of all values matching the key."""
11631149 if default is not sentinel :
11641150 return self ._md .getall (key , default )
@@ -1168,10 +1154,8 @@ def getall(
11681154 @overload
11691155 def getone (self , key : str ) -> _V : ...
11701156 @overload
1171- def getone (self , key : str , default : _T ) -> Union [_V , _T ]: ...
1172- def getone (
1173- self , key : str , default : Union [_T , _SENTINEL ] = sentinel
1174- ) -> Union [_V , _T ]:
1157+ def getone (self , key : str , default : _T ) -> _V | _T : ...
1158+ def getone (self , key : str , default : _T | _SENTINEL = sentinel ) -> _V | _T :
11751159 """Get first value matching the key.
11761160
11771161 Raises KeyError if the key is not found and no default is provided.
@@ -1187,10 +1171,10 @@ def __getitem__(self, key: str) -> _V:
11871171 return self .getone (key )
11881172
11891173 @overload
1190- def get (self , key : str , / ) -> Union [ _V , None ] : ...
1174+ def get (self , key : str , / ) -> _V | None : ...
11911175 @overload
1192- def get (self , key : str , / , default : _T ) -> Union [ _V , _T ] : ...
1193- def get (self , key : str , default : Union [ _T , None ] = None ) -> Union [ _V , _T , None ] :
1176+ def get (self , key : str , / , default : _T ) -> _V | _T : ...
1177+ def get (self , key : str , default : _T | None = None ) -> _V | _T | None :
11941178 """Get first value matching the key.
11951179
11961180 If the key is not found, returns the default (or None if no default is provided)
@@ -1234,7 +1218,7 @@ def copy(self) -> MultiDict[_V]:
12341218class CIMultiDictProxy (_CIMixin , MultiDictProxy [_V ]):
12351219 """Read-only proxy for CIMultiDict instance."""
12361220
1237- def __init__ (self , arg : Union [ MultiDict [_V ], MultiDictProxy [_V ] ]):
1221+ def __init__ (self , arg : MultiDict [_V ] | MultiDictProxy [_V ]):
12381222 if not isinstance (arg , (CIMultiDict , CIMultiDictProxy )):
12391223 raise TypeError (
12401224 "ctor requires CIMultiDict or CIMultiDictProxy instance"
@@ -1248,7 +1232,7 @@ def copy(self) -> CIMultiDict[_V]:
12481232 return CIMultiDict (self ._md )
12491233
12501234
1251- def getversion (md : Union [ MultiDict [object ], MultiDictProxy [object ] ]) -> int :
1235+ def getversion (md : MultiDict [object ] | MultiDictProxy [object ]) -> int :
12521236 if isinstance (md , MultiDictProxy ):
12531237 md = md ._md
12541238 elif not isinstance (md , MultiDict ):
0 commit comments