Skip to main content

A Python library that supplies runtime-checkable, fully parameterized, and well-documented protocols for nearly all dunder methods/attributes.

Project description

Install

$ pip install supportsx

Description

A Python library that supplies runtime-checkable, fully parameterized, and well-documented protocols for nearly all dunder methods/attributes that are not available by default on types and objects.

The goal of this library is to expand what is already available in the typing standard library and _typeshed library, as well as add a number of common union protocols. The full list of available protocols can be found in the documentation section.

Example

from typing import Any
import supportsx

def foo(
    value: supportsx.add[Any, int],
    ctm: supportsx.u.ctx_mngr
) -> None:
    with ctm:
        print(value + 1)
from typing import Any
from supportsx import *

def foo(
    value: SupportsAdd[Any, int],
    ctm: SupportsContextManager
) -> None:
    with ctm:
        print(value + 1)

As shown above, there are two ways of referencing each protocol. The preferred method is the one shown first (i.e. supportsx.* for primary protocols and supportsx.u.* for union protocols), as it helps keep the global namespace clear (although at the end of the day, it is up to you).

Documentation

Available Protocols

Below is an exhaustive list all available protocols, which methods/attributes they represent, and the available parameters:

Primary protocols

Protocol Method/Attribute Parameter Order Parameter Form
supportsx.abs
supportsx.SupportsAbs
__abs__ [_T_co] () -> _T_co
supportsx.add
supportsx.SupportsAdd
__add__ [_T_contra, _T_co] (_T_contra) -> _T_co
supportsx.aenter
supportsx.SupportsAEnter
__aenter__ [_T_co] () -> Awaitable[_T_co]
supportsx.aexit
supportsx.SupportsAExit
__aexit__ (Type[BaseException] | None, BaseException | None, TracebackType | None) -> Awaitable[None]
supportsx.aiter
supportsx.SupportsAIter
__aiter__ [_T_co] () -> AsyncIterator[_T_co]
supportsx.and_
supportsx.SupportsAnd
__and__ [_T_contra, _T_co] (_T_contra) -> _T_co
supportsx.anext
supportsx.SupportsANext
__anext__ [_T_co] () -> Awaitable[_T_co]
supportsx.await_
supportsx.SupportsAwait
__await__ [_T_co] () -> Iterator[_T_co]
supportsx.bool
supportsx.SupportsBool
__bool__ () -> bool
supportsx.buffer
supportsx.SupportsBuffer
__buffer__ (int) -> memoryview
supportsx.bytes
supportsx.SupportsBytes
__bytes__ () -> bytes
supportsx.call
supportsx.SupportsCall
__call__ [_P, _T_co] (_P) -> _T_co
supportsx.ceil
supportsx.SupportsCeil
__ceil__ () -> Integral
supportsx.complex
supportsx.SupportsComplex
__complex__ () -> complex
supportsx.contains
supportsx.SupportsContains
__contains__ [_T_contra] (_T_contra) -> bool
supportsx.delete
supportsx.SupportsDelete
__delete__ [_T_contra] (_T_contra) -> None
supportsx.delitem
supportsx.SupportsDelItem
__delitem__ [_T_contra] (_T_contra) -> None
supportsx.divmod
supportsx.SupportsDivMod
__divmod__ [_T_contra, _T_co] (_T_contra) -> _T_co
supportsx.enter
supportsx.SupportsEnter
__enter__ [_T_co] () -> _T_co
supportsx.exit
supportsx.SupportsExit
__exit__ (Type[BaseException] | None, BaseException | None, TracebackType | None) -> None
supportsx.float
supportsx.SupportsFloat
__float__ () -> float
supportsx.floor
supportsx.SupportsFloor
__floor__ () -> Integral
supportsx.floordiv
supportsx.SupportsFloorDiv
__floordiv__ [_T_contra, _T_co] (_T_contra) -> _T_co
supportsx.ge
supportsx.SupportsGE
__ge__ [_T_contra] (_T_contra) -> bool
supportsx.get
supportsx.SupportsGet
__get__ [_T_contra, _T_co] (_T_contra | None, Type[_T_contra] | None = None) -> _T_co
supportsx.getattr
supportsx.SupportsGetAttr
__getattr__ [_T_co] (str) -> _T_co
supportsx.getitem
supportsx.SupportsGetItem
__getitem__ [_T_contra, _T_co] (_T_contra) -> _T_co
supportsx.gt
supportsx.SupportsGT
__gt__ [_T_contra] (_T_contra) -> bool
supportsx.iadd
supportsx.SupportsIAdd
__iadd__ [_T_contra] (_T_contra) -> None
supportsx.iand
supportsx.SupportsIAnd
__iand__ [_T_contra] (_T_contra) -> None
supportsx.ifloordiv
supportsx.SupportsIFloorDiv
__ifloordiv__ [_T_contra] (_T_contra) -> None
supportsx.ilshift
supportsx.SupportsILShift
__ilshift__ [_T_contra] (_T_contra) -> None
supportsx.imatmul
supportsx.SupportsIMatMul
__imatmul__ [_T_contra] (_T_contra) -> None
supportsx.imod
supportsx.SupportsIMod
__imod__ [_T_contra] (_T_contra) -> None
supportsx.imul
supportsx.SupportsIMul
__imul__ [_T_contra] (_T_contra) -> None
supportsx.index
supportsx.SupportsIndex
__index__ () -> int
supportsx.int
supportsx.SupportsInt
__int__ () -> int
supportsx.invert
supportsx.SupportsInvert
__invert__ [_T_co] () -> _T_co
supportsx.ior
supportsx.SupportsIOr
__ior__ [_T_contra] (_T_contra) -> None
supportsx.ipow
supportsx.SupportsIPow
__ipow__ [_T_contra, _T2_contra] (_T_contra, _T2_contra | None = None) -> None
supportsx.irshift
supportsx.SupportsIRShift
__irshift__ [_T_contra] (_T_contra) -> None
supportsx.isub
supportsx.SupportsISub
__isub__ [_T_contra] (_T_contra) -> None
supportsx.iter
supportsx.SupportsIter
__iter__ [_T_co] () -> Iterator[_T_co]
supportsx.itruediv
supportsx.SupportsITrueDiv
__itruediv__ [_T_contra] (_T_contra) -> None
supportsx.ixor
supportsx.SupportsIXor
__ixor__ [_T_contra] (_T_contra) -> None
supportsx.le
supportsx.SupportsLE
__le__ [_T_contra] (_T_contra) -> bool
supportsx.len
supportsx.SupportsLen
__len__ () -> int
supportsx.length_hint
supportsx.SupportsLengthHint
__length_hint__ () -> int
supportsx.lshift
supportsx.SupportsLShift
__lshift__ [_T_contra, _T_co] (_T_contra) -> _T_co
supportsx.lt
supportsx.SupportsLT
__lt__ [_T_contra] (_T_contra) -> bool
supportsx.match_args
supportsx.SupportsMatchArgs
__match_args__ () -> Sequence[str]
supportsx.matmul
supportsx.SupportsMatMul
__matmul__ [_T_contra, _T_co] (_T_contra) -> _T_co
supportsx.missing
supportsx.SupportsMissing
__missing__ [_T_contra, _T_co] (_T_contra) -> _T_co
supportsx.mod
supportsx.SupportsMod
__mod__ [_T_contra, _T_co] (_T_contra) -> _T_co
supportsx.mro_entries
supportsx.SupportsMroEntries
__mro_entries__ [_T] (Sequence[_T]) -> Sequence[_T]
supportsx.mul
supportsx.SupportsMul
__mul__ [_T_contra, _T_co] (_T_contra) -> _T_co
supportsx.neg
supportsx.SupportsNeg
__neg__ [_T_co] () -> _T_co
supportsx.next
supportsx.SupportsNext
__next__ [_T_co] () -> _T_co
supportsx.objclass
supportsx.SupportsObjClass
__objclass__ [_T_co] () -> Type[_T_co]
supportsx.or_
supportsx.SupportsOr
__or__ [_T_contra, _T_co] (_T_contra) -> _T_co
supportsx.pos
supportsx.SupportsPos
__pos__ [_T_co] () -> _T_co
supportsx.post_init
supportsx.SupportsPostInit
__post_init__ [_P] (_P) -> None
supportsx.pow
supportsx.SupportsPow
__pow__ [_T_contra, _T2_contra, _T_co] (_T_contra, _T2_contra | None = None) -> _T_co
supportsx.radd
supportsx.SupportsRAdd
__radd__ [_T_contra, _T_co] (_T_contra) -> _T_co
supportsx.rand
supportsx.SupportsRAnd
__rand__ [_T_contra, _T_co] (_T_contra) -> _T_co
supportsx.rdivmod
supportsx.SupportsRDivMod
__rdivmod__ [_T_contra, _T_co] (_T_contra) -> _T_co
supportsx.release_buffer
supportsx.SupportsReleaseBuffer
__release_buffer__ (memoryview) -> None
supportsx.reversed
supportsx.SupportsReversed
__reversed__ [_T_co] () -> Iterator[_T_co]
supportsx.rfloordiv
supportsx.SupportsRFloorDiv
__rfloordiv__ [_T_contra, _T_co] (_T_contra) -> _T_co
supportsx.rlshift
supportsx.SupportsRLShift
__rlshift__ [_T_contra, _T_co] (_T_contra) -> _T_co
supportsx.rmatmul
supportsx.SupportsRMatMul
__rmatmul__ [_T_contra, _T_co] (_T_contra) -> _T_co
supportsx.rmod
supportsx.SupportsRMod
__rmod__ [_T_contra, _T_co] (_T_contra) -> _T_co
supportsx.rmul
supportsx.SupportsRMul
__rmul__ [_T_contra, _T_co] (_T_contra) -> _T_co
supportsx.ror
supportsx.SupportsROr
__ror__ [_T_contra, _T_co] (_T_contra) -> _T_co
supportsx.round
supportsx.SupportsRound
__round__ (int | None = None) -> Integral
supportsx.rpow
supportsx.SupportsRPow
__rpow__ [_T_contra, _T2_contra, _T_co] (_T_contra, _T2_contra | None = None) -> _T_co
supportsx.rrshift
supportsx.SupportsRRShift
__rrshift__ [_T_contra, _T_co] (_T_contra) -> _T_co
supportsx.rshift
supportsx.SupportsRShift
__rshift__ [_T_contra, _T_co] (_T_contra) -> _T_co
supportsx.rsub
supportsx.SupportsRSub
__rsub__ [_T_contra, _T_co] (_T_contra) -> _T_co
supportsx.rtruediv
supportsx.SupportsRTrueDiv
__rtruediv__ [_T_contra, _T_co] (_T_contra) -> _T_co
supportsx.rxor
supportsx.SupportsRXor
__rxor__ [_T_contra, _T_co] (_T_contra) -> _T_co
supportsx.set
supportsx.SupportsSet
__set__ [_T_contra, _T2_contra] (_T_contra, _T2_contra) -> None
supportsx.setitem
supportsx.SupportsSetItem
__setitem__ [_T_contra, _T2_contra] (_T_contra, _T2_contra) -> None
supportsx.set_name
supportsx.SupportsSetName
__set_name__ [_T_contra] (Type[_T_contra], str) -> None
supportsx.sub
supportsx.SupportsSub
__sub__ [_T_contra, _T_co] (_T_contra) -> _T_co
supportsx.truediv
supportsx.SupportsTrueDiv
__truediv__ [_T_contra, _T_co] (_T_contra) -> _T_co
supportsx.trunc
supportsx.SupportsTrunc
__trunc__ () -> Integral
supportsx.xor
supportsx.SupportsXor
__xor__ [_T_contra, _T_co] (_T_contra) -> _T_co

Union Protocols

Protocol Parameters (in order) Bases
supportsx.u.actx_mngr
supportsx.SupportsAsyncContextManager
supportsx.u.SupportsAsyncContextManager
[_T_co] SupportsAEnter[_T_co]
SupportsAExit
supportsx.u.bitops
supportsx.SupportsBitwiseOps
supportsx.u.SupportsBitwiseOps
[_T_contra, _T_co] SupportsAnd[_T_contra, _T_co]
SupportsLShift[_T_contra, _T_co]
SupportsOr[_T_contra, _T_co]
SupportsRAnd[_T_contra, _T_co]
SupportsRLShift[_T_contra, _T_co]
SupportsROr[_T_contra, _T_co]
SupportsRRShift[_T_contra, _T_co]
SupportsRShift[_T_contra, _T_co]
SupportsRXor[_T_contra, _T_co]
SupportsXor[_T_contra, _T_co]
supportsx.u.cmps
supportsx.SupportsComparisons
supportsx.u.SupportsComparisons
[_T_contra] SupportsGE[_T_contra]
SupportsGT[_T_contra]
SupportsLE[_T_contra]
SupportsLT[_T_contra]
supportsx.u.ctx_mngr
supportsx.SupportsContextManager
supportsx.u.SupportsContextManager
[_T_co] SupportsEnter[_T_co]<br>SupportsExit
supportsx.u.data_desc
supportsx.SupportsDataDescriptor
supportsx.u.SupportsDataDescriptor
[_T_contra, _T2_contra, _T_co] SupportsDelete[_T_contra]
SupportsGet[_T_contra, _T_co]
SupportsSet[_T_contra, _T2_contra]
supportsx.u.ibitops
supportsx.SupportsIBitwiseOps
supportsx.u.SupportsIBitwiseOps
[_T_contra] SupportsIAnd[_T_contra]
SupportsILShift[_T_contra]
SupportsIOr[_T_contra]
SupportsIRShift[_T_contra]
SupportsIXor[_T_contra]
supportsx.u.imathops
supportsx.SupportsIMathOps
supportsx.u.SupportsIMathOps
[_T_contra, _T2_contra] SupportsIAdd[_T_contra]
SupportsIFloorDiv[_T_contra]
SupportsIMod[_T_contra]
SupportsIMul[_T_contra]
SupportsIPow[_T_contra, _T2_contra]
SupportsISub[_T_contra]
SupportsITrueDiv[_T_contra]
supportsx.u.imathops2
supportsx.SupportsIMathOps2
supportsx.u.SupportsIMathOps2
[_T_contra, _T2_contra] SupportsIMathOps[_T_contra, _T2_contra]
SupportsIMatMul[_T_contra]
supportsx.u.items
supportsx.SupportsItems
supportsx.u.SupportsItems
[_T_contra, _T2_contra, _T_co] SupportsDelItem[_T_contra]
SupportsGetItem[_T_contra, _T_co]
SupportsSetItem[_T_contra, _T2_contra]
supportsx.u.length
supportsx.SupportsLength
supportsx.u.SupportsLength
SupportsLen
SupportsLengthHint
supportsx.u.math_funcs
supportsx.SupportsMathFunctions
supportsx.u.SupportsMathFunctions
[_T_contra, _T_co, _T2_co] SupportsAbs[_T2_co]
SupportsCeil
SupportsDivMod[_T_contra, _T_co]
SupportsFloor
SupportsRDivMod[_T_contra, _T_co]
SupportsRound
SupportsTrunc
supportsx.u.mathops
supportsx.SupportsMathOps
supportsx.u.SupportsMathOps
[_T_contra, _T2_contra, _T_co] SupportsAdd[_T_contra, _T_co]
SupportsFloorDiv[_T_contra, _T_co]
SupportsMod[_T_contra, _T_co]
SupportsMul[_T_contra, _T_co]
SupportsPow[_T_contra, _T2_contra, _T_co]
SupportsRAdd[_T_contra, _T_co]
SupportsRFloorDiv[_T_contra, _T_co]
SupportsRMod[_T_contra, _T_co]
SupportsRMul[_T_contra, _T_co]
SupportsRPow[_T_contra, _T2_contra, _T_co]
SupportsRSub[_T_contra, _T_co]
SupportsRTrueDiv[_T_contra, _T_co]
SupportsSub[_T_contra, _T_co]
SupportsTrueDiv[_T_contra, _T_co]
supportsx.u.mathops2
supportsx.SupportsMathOps2
supportsx.u.SupportsMathOps2
[_T_contra, _T2_contra, _T_co] SupportsMathOps[_T_contra, _T2_contra, _T_co]
SupportsMatMul[_T_contra, _T_co]
SupportsRMatMul[_T_contra, _T_co]
supportsx.u.type_conversion
supportsx.SupportsTypeConversion
supportsx.u.SupportsTypeConversion
SupportsBytes
SupportsComplex
SupportsFloat
SupportsIndex
SupportsInt
supportsx.u.type_conversion2
supportsx.SupportsTypeConversion2
supportsx.u.SupportsTypeConversion2
SupportsBool
SupportsTypeConversion
supportsx.u.unary_ops
supportsx.SupportsUnaryOps
supportsx.u.SupportsUnaryOps
[_T_co] SupportsInvert[_T_co]
SupportsNeg[_T_co]
SupportsPos[_T_co]

Excluded Methods and Attributes

The following methods are available on all objects, and are thus excluded:

__delattr__
__dir__
__eq__
__format__
__getattribute__
__getstate__
__hash__
__init__
__init_subclass__
__ne__
__new__
__reduce__
__reduce_ex__
__repr__
__setattr__
__sizeof__
__str__
__subclasshook__

The following methods are available on all types, and are thus excluded:

__instancecheck__
__prepare__
__subclasscheck__
__subclasses__
mro

The following attributes are available on all types, and are thus excluded:

__base__
__bases__
__basicsize__
__class__
__dictoffset__
__flags__
__itemsize__
__module__
__mro__
__name__
__qualname__
__text_signature__
__type_params__
__weakrefoffset__

Although __slots__ and __dict__ may not appear on an object, protocols for those objects are not currently supported by the Python specification due to the part they play in attribute access.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

supportsx-0.0.1.tar.gz (28.5 kB view details)

Uploaded Source

Built Distribution

supportsx-0.0.1-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file supportsx-0.0.1.tar.gz.

File metadata

  • Download URL: supportsx-0.0.1.tar.gz
  • Upload date:
  • Size: 28.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for supportsx-0.0.1.tar.gz
Algorithm Hash digest
SHA256 28013102c664f93fa3b7630ef57a6a28378a916c44e95bf2991417c480c51982
MD5 29e26e09865cd2eafcb9fbac6f767e4c
BLAKE2b-256 70b71452c6b2aa9885767c28e810395665b68e52f24056e83ac713ec16371d68

See more details on using hashes here.

File details

Details for the file supportsx-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: supportsx-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 21.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for supportsx-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4f06e890dfac7ab4384243df71e3127d616da1d6be5227aaf4359111081959a2
MD5 d4fd5c8a830eab364abbfa9f27a03a9c
BLAKE2b-256 41fdc0b8cce2f4acfd728644b47e6202e5c98fda24619a3274f6770ac25a986b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page