Why make this?
TL;DR: I like nice types and I wanted to try mkdocs.
Python's Sum
Python's current sum function requires types to choose one of the following:
# The bad: verbose calls
sum(iterable, start_value)
This allows type annotations to be clean, but it feels bad.
# The ugly: gross type annotations
class SupportsSum:
# int is ugly
def __radd__(self, other: int | SupportsSum):
if other == 0:
return self
...
This allows short sum calls, but it feels wrong from a type
checking perspective.
Trying Mkdocs
I've used Sphinx while working on Arcade and pyglet, but I wanted to explore other documentation systems.
Other Inspiration
As of pyglet 2.1's dev previews, pyglet.math contains:
- comments explaining how Pythons' sum uses
0as a start value - pyglet.math types which support sum by allowing __radd__ to take an int value.