Modernize code to Python 3.6+ and some cleanup
This commit is contained in:
@@ -8,17 +8,17 @@ if len(sys.argv) == 2:
|
||||
module_name = sys.argv[1].replace('.py', '')
|
||||
module = importlib.import_module(module_name)
|
||||
else:
|
||||
print('Usage: {} <vector-module-to-test>'.format())
|
||||
print(f'Usage: {sys.argv[0]} <vector-module-to-test>')
|
||||
sys.exit(1)
|
||||
|
||||
fmt = 'Selected Vector2d type: {.__name__}.{.__name__}'
|
||||
print(fmt.format(module, module.Vector2d))
|
||||
|
||||
mem_init = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
|
||||
print('Creating {:,} Vector2d instances'.format(NUM_VECTORS))
|
||||
print(f'Creating {NUM_VECTORS:,} Vector2d instances')
|
||||
|
||||
vectors = [module.Vector2d(3.0, 4.0) for i in range(NUM_VECTORS)]
|
||||
|
||||
mem_final = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
|
||||
print('Initial RAM usage: {:14,}'.format(mem_init))
|
||||
print(' Final RAM usage: {:14,}'.format(mem_final))
|
||||
print(f'Initial RAM usage: {mem_init:14,}')
|
||||
print(f' Final RAM usage: {mem_final:14,}')
|
||||
|
||||
@@ -18,7 +18,7 @@ public class Expose {
|
||||
System.out.println("message.secret = " + wasHidden);
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
// this will not happen after setAcessible(true)
|
||||
// this will not happen after setAccessible(true)
|
||||
System.err.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@ import Confidential
|
||||
message = Confidential('top secret text')
|
||||
secret_field = Confidential.getDeclaredField('secret')
|
||||
secret_field.setAccessible(True) # break the lock!
|
||||
print 'message.secret =', secret_field.get(message)
|
||||
print('message.secret =', secret_field.get(message))
|
||||
|
||||
@@ -7,5 +7,5 @@ for field in fields:
|
||||
# list private fields only
|
||||
if Modifier.isPrivate(field.getModifiers()):
|
||||
field.setAccessible(True) # break the lock
|
||||
print 'field:', field
|
||||
print '\t', field.getName(), '=', field.get(message)
|
||||
print('field:', field)
|
||||
print('\t', field.getName(), '=', field.get(message))
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
"""
|
||||
In the Jython registry file there is this line:
|
||||
|
||||
@@ -14,4 +13,4 @@ message = Confidential('top secret text')
|
||||
for name in dir(message):
|
||||
attr = getattr(message, name)
|
||||
if not callable(attr): # non-methods only
|
||||
print name + '\t=', attr
|
||||
print(name + '\t=', attr)
|
||||
|
||||
@@ -81,7 +81,7 @@ Tests of hashing:
|
||||
>>> v2 = Vector2d(3.1, 4.2)
|
||||
>>> hash(v1), hash(v2)
|
||||
(7, 384307168202284039)
|
||||
>>> len(set([v1, v2]))
|
||||
>>> len({v1, v2})
|
||||
2
|
||||
|
||||
"""
|
||||
|
||||
@@ -83,7 +83,7 @@ Tests of hashing:
|
||||
>>> v2 = Vector2d(3.1, 4.2)
|
||||
>>> hash(v1), hash(v2)
|
||||
(7, 384307168202284039)
|
||||
>>> len(set([v1, v2]))
|
||||
>>> len({v1, v2})
|
||||
2
|
||||
|
||||
# end::VECTOR2D_V3_DEMO[]
|
||||
|
||||
@@ -80,7 +80,7 @@ Tests of hashing:
|
||||
>>> v2 = Vector2d(3.1, 4.2)
|
||||
>>> hash(v1), hash(v2)
|
||||
(7, 384307168202284039)
|
||||
>>> len(set([v1, v2]))
|
||||
>>> len({v1, v2})
|
||||
2
|
||||
|
||||
# end::VECTOR2D_V3_DEMO[]
|
||||
|
||||
Reference in New Issue
Block a user