Commit e1ce5480 authored by Stefan Behnel's avatar Stefan Behnel

Make type identifier escaping deterministic: hash() hashing lead to...

Make type identifier escaping deterministic: hash() hashing lead to unpredictable random prefixes for long names across multiple Python runs.
parent 5cdd8e2d
......@@ -4,8 +4,8 @@
from __future__ import absolute_import
import collections
import copy
import hashlib
import re
try:
......@@ -4731,5 +4731,5 @@ def type_identifier(type):
def cap_length(s, max_prefix=63, max_len=1024):
if len(s) <= max_prefix:
return s
else:
return '%x__%s__etc' % (abs(hash(s)) % (1<<20), s[:max_len-17])
hash_prefix = hashlib.sha256(s.encode('ascii')).hexdigest()[:6]
return '%s__%s__etc' % (hash_prefix, s[:max_len-17])
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment