Modernize code to Python 3.6+ and some cleanup

This commit is contained in:
Miroslav Šedivý
2021-01-31 22:48:38 +01:00
parent 93bb4407fa
commit b69e0c2023
86 changed files with 153 additions and 189 deletions

View File

@@ -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))