mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
bpo-36972: Add SupportsIndex (GH-13448)
In order to support typing checks calling hex(), oct() and bin() on user-defined classes, a SupportIndex protocol is required. The ability to check these at runtime would be good to add for completeness sake. This is pretty much just a copy of SupportsInt with the names tweaked.
This commit is contained in:
parent
33e71e01e9
commit
4c7a46eb3c
5 changed files with 21 additions and 0 deletions
|
@ -74,6 +74,7 @@ __all__ = [
|
|||
'SupportsBytes',
|
||||
'SupportsComplex',
|
||||
'SupportsFloat',
|
||||
'SupportsIndex',
|
||||
'SupportsInt',
|
||||
'SupportsRound',
|
||||
|
||||
|
@ -1304,6 +1305,14 @@ class SupportsBytes(_Protocol):
|
|||
pass
|
||||
|
||||
|
||||
class SupportsIndex(_Protocol):
|
||||
__slots__ = ()
|
||||
|
||||
@abstractmethod
|
||||
def __index__(self) -> int:
|
||||
pass
|
||||
|
||||
|
||||
class SupportsAbs(_Protocol[T_co]):
|
||||
__slots__ = ()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue