fix generic typed dict `TypeError` on Python 3.10
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by jorenham · committed by jorenham · parent 77bd81f · Browse files · 1 file·+40 added−11 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+40 added−11 removed
- other:+40 added−11 removed
Provenance
- Commit
9a2d169- Tree
472516f- Author
jorenham <jhammudoglu@gmail.com>- Committer
jorenham <jhammudoglu@gmail.com>- Parent
77bd81f
1 file changed+40 added−11 removed
modified:src/click/types.py+40 added-11 removed
187 unmodified lines188 @abc.abstractmethod189 def arity(self) -> int: ... # type: ignore[override]190 191 192-class FuncParamTypeInfoDict(ParamTypeInfoDict, t.Generic[_ValueT_contra, _ValueT_co]):193- func: t.Callable[[_ValueT_contra], _ValueT_co]192+if t.TYPE_CHECKING:193+ # on Python 3.10 this will raise a TypeError194 195+ class FuncParamTypeInfoDict(196+ ParamTypeInfoDict,197+ t.Generic[_ValueT_contra, _ValueT_co],198+ ):199+ func: t.Callable[[_ValueT_contra], _ValueT_co]200+else:201 202+ class FuncParamTypeInfoDict(ParamTypeInfoDict):203+ func: t.Callable[[t.Any], t.Any]204+205+206 class FuncParamType(ParamType[_ValueT_co], t.Generic[_ValueT_contra, _ValueT_co]):207 name: str208 func: t.Callable[[_ValueT_contra], _ValueT_co]209 57 unmodified lines267 def __repr__(self) -> str:268 return "STRING"269 270 261-class ChoiceInfoDict(ParamTypeInfoDict, t.Generic[_ValueT_co]):262- choices: tuple[_ValueT_co, ...]263- case_sensitive: bool271+if t.TYPE_CHECKING:272+ # on Python 3.10 this will raise a TypeError273 274+ class ChoiceInfoDict(ParamTypeInfoDict, t.Generic[_ValueT_co]):275+ choices: tuple[_ValueT_co, ...]276+ case_sensitive: bool277+else:278 279+ class ChoiceInfoDict(ParamTypeInfoDict):280+ choices: tuple[t.Any, ...]281+ case_sensitive: bool282+283+284 class Choice(ParamType[_ValueT_co], t.Generic[_ValueT_co]):285 """The choice type allows a value to be checked against a fixed set286 of supported values.287 263 unmodified lines551 ctx,552 )553 554 537-class NumberRangeInfoDict(ParamTypeInfoDict, t.Generic[_FloatValueT_co]):538- min: _FloatValueT_co | None539- max: _FloatValueT_co | None540- min_open: bool541- max_open: bool542- clamp: bool555+if t.TYPE_CHECKING:556+ # on Python 3.10 this will raise a TypeError557 558+ class NumberRangeInfoDict(ParamTypeInfoDict, t.Generic[_FloatValueT_co]):559+ min: _FloatValueT_co | None560+ max: _FloatValueT_co | None561+ min_open: bool562+ max_open: bool563+ clamp: bool564+else:565 566+ class NumberRangeInfoDict(ParamTypeInfoDict):567+ min: t.Any | None568+ max: t.Any | None569+ min_open: bool570+ max_open: bool571+ clamp: bool572+573+574 class _NumberRangeBase(575 _NumberParamTypeBase[_ValueT_contra, _FloatValueT_co],576 t.Generic[_ValueT_contra, _FloatValueT_co],577 ):797 unmodified lines