logoalt Hacker News

laurentlb12/09/20240 repliesview on HN

Try this in Python:

id("ab") # not deterministic

hash("ab") # not deterministic

def foo(): pass

str(foo) # not deterministic

Another sneaky one is the `is` operator in Python, where the Python documentation says:

> Due to automatic garbage-collection, free lists, and the dynamic nature of descriptors, you may notice seemingly unusual behaviour in certain uses of the `is` operator

Related to that is the `__del__` method: when exactly is it called?

It's quite easy to get non-deterministic code in Python and in many languages. And of course, there are lots of non-deterministic functions in the standard library (Starlark doesn't provide them).