[New-bugs-announce] [issue19224] Make hash(None) consistent among processes

Qiangning Hong report at bugs.python.org
Fri Oct 11 06:03:41 CEST 2013

New submission from Qiangning Hong:

Integers, strings, and bool's hash are all consistent for processes of a same interpreter.  However, hash(None) differs.

$ python -c "print(hash(None))"
$ python -c "print(hash(None))"

It's wired and make difficulty for distributed systems partitioning data according hash of keys if the system wants the keys support None.

This patch makes hash(None) always return 0 to resolve that problem.  And it is used in DPark(Python clone of Spark, a MapReduce alike framework in Python, https://github.com/douban/dpark) to speed up portable hash (see line https://github.com/douban/dpark/blob/65a3ba857f11285667c61e2e134dacda44c13a2c/dpark/util.py#L47).

davies.liu at gmail.com is the original author of this patch.  All credit goes to him.

messages: 199439
nosy: hongqn
priority: normal
severity: normal
status: open
title: Make hash(None) consistent among processes

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list