Modernize code to Python 3.6+ and some cleanup
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
import sys
|
||||
|
||||
MAX_BITS = len(format(sys.maxsize, 'b'))
|
||||
print('%s-bit Python build' % (MAX_BITS + 1))
|
||||
print(f'{MAX_BITS + 1}-bit Python build')
|
||||
|
||||
def hash_diff(o1, o2):
|
||||
h1 = '{:>0{}b}'.format(hash(o1), MAX_BITS)
|
||||
h2 = '{:>0{}b}'.format(hash(o2), MAX_BITS)
|
||||
h1 = f'{hash(o1):>0{MAX_BITS}b}'
|
||||
h2 = f'{hash(o2):>0{MAX_BITS}b}'
|
||||
diff = ''.join('!' if b1 != b2 else ' ' for b1, b2 in zip(h1, h2))
|
||||
count = '!= {}'.format(diff.count('!'))
|
||||
count = f'!= {diff.count("!")}'
|
||||
width = max(len(repr(o1)), len(repr(o2)), 8)
|
||||
sep = '-' * (width * 2 + MAX_BITS)
|
||||
return '{!r:{width}} {}\n{:{width}} {} {}\n{!r:{width}} {}\n{}'.format(
|
||||
o1, h1, ' ' * width, diff, count, o2, h2, sep, width=width)
|
||||
return (f'{o1!r:{width}} {h1}\n{" ":{width}} {diff} {count}\n'
|
||||
f'{o2!r:{width}} {h2}\n{sep}')
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(hash_diff(1, 1.0))
|
||||
|
||||
Reference in New Issue
Block a user