The CPython implementation of Python stores constant values (such as numbers, strings, tuples or frozensets) used in a function as an optimization. You can observe them via func.__code__.co_consts
:
>>> def get_tuple():
... return (1,)
...
>>> get_tuple.__code__.co_consts
(None, 1, (1,))
As you can see, for this function the constants None
(which is the default return value), 1
and (1,)
get stored. Since the function returns one of them, you get the exact same object with every call.
Because this is a CPython implementation detail, it's not guaranteed by the Python language. That's probably why you couldn't find it in the documentation :)