Skip to main content

Trite hacks for use with typing.

Project description

Trite hacks for use with typing.

Latest release 20260525: Sortable and EQSortable Protocols which support lt and both eq and lt respectively.

Short summary:

  • EQSortable: A type whose instances can be sorted and also tested for equality i.e.
  • is_optional: Check if annotation is an Optional[type]. Return type if so, None otherwise.
  • Sortable: A type whose instances can be sorted i.e.
  • subtype: Construct a TypeVar for subtypes of the type t.

Module contents:

  • class EQSortable(typing.Protocol): A type whose instances can be sorted and also tested for equality i.e. support the < and == operators.

  • is_optional(annotation): Check if annotation is an Optional[type]. Return type if so, None otherwise.

  • class Sortable(typing.Protocol): A type whose instances can be sorted i.e. support the < operator.

  • subtype(t, name=None): Construct a TypeVar for subtypes of the type t.

    Parameters:

    • t: the type which bounds the TypeVar
    • name: optional name for the TypeVar, default t.__name__ + 'SubType'

Release Log

Release 20260525: Sortable and EQSortable Protocols which support lt and both eq and lt respectively.

Release 20250503: is_optional: bugfix: Optional[T] has a get_args of (T,), not (T,None).

Release 20250428: New is_optional(annotation) function to recognise Optional[type] annotations, returning type if true, None otherwise.

Release 20230331: Initial release.

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

cs_typingutils-20260525.tar.gz (2.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cs_typingutils-20260525-py2.py3-none-any.whl (2.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file cs_typingutils-20260525.tar.gz.

File metadata

  • Download URL: cs_typingutils-20260525.tar.gz
  • Upload date:
  • Size: 2.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for cs_typingutils-20260525.tar.gz
Algorithm Hash digest
SHA256 3ae520c9f26558fd2ef2a229fa794b3ef6732fc7389f23dea9e8868a2084a783
MD5 34e583445e9d3dfd58124243130dcec9
BLAKE2b-256 d82f1766e9b372a08bfd5294648524aa6dfaa2b13b5739d144aee78e7c501f99

See more details on using hashes here.

File details

Details for the file cs_typingutils-20260525-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for cs_typingutils-20260525-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b046a91d38b9630333cb48f9f2bb7910f4232b0f3f62aadcd640672504371de5
MD5 1579c9cc665dc1f2a8e812088ada0e00
BLAKE2b-256 6469928454e78999d302d0cab5a473927c02a81721e2ada112fc71c20bb6e9bd

See more details on using hashes here.

Supported by

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