some python utilities that may be useful to some people
Find a file
2026-05-31 20:46:02 +02:00
utils cache decorator (probably use functools.cache though) 2026-05-31 20:46:02 +02:00
.gitignore formatting and doxygen 2024-06-14 22:59:34 +02:00
Doxyfile formatting and doxygen 2024-06-14 22:59:34 +02:00
LICENSE added a license...? 2021-07-30 09:43:20 +02:00
README.md updated README 2024-06-14 20:15:38 +02:00
setup.py added setuptools stuff, .gitignore 2020-09-20 21:23:55 +02:00

Python Utilities I wrote

This repository contains a few python utilities I think may be useful to some people, but really they're mostly funny coding exercises I posed myself. They do things like make a callable strict (that is, only allow it to accept and return the types given in its annotations, if those exist) (see utils.decorators.strict)

modules

Currently I have some decorators, some things to do with types, and a cache module

decorators

  • overload allows you to specify different implementations of a function based on the types given to it
  • strict allows you to make a function strict, as described above
  • template allows you to make a "class template", as seen in C++ (except of course, everything in python happens at runtime, including type creation)
  • convert allows you to convert any or all arguments to a function using converter function annotations
  • factory lets you specify factory functions for function parameters
  • auto_slots creates a __slots__ class attribute from assignments in the class' __init__ method
  • contracts lets you check functions' contracts at runtime, erroring if they are not obeyed (both preconditions and postconditions can be checked)
  • evaluated immediately evaluates the decorated function with given arguments

types

  • NaturalNumber and StrictNaturalNumber
  • my own isinstance function that lets you check Union types as well

cache

  • a cache decorator that lets you specify a cache policy at function call time