Shell: do not access properties on startup

Change the way the shell finds methods to add to the locals on startup: the
methods are queried on the object’s class, rather than the object itself. This
allows detecting if an object’s member is a property and ignore it, rather than
accessing the property.

Attributes whose name starts by ‘_’ are also now ignored, which avoids
importing private methods or Python magic methods in the shell namespace.

Fixes spurious accesses to ProxyUtils’s SIMD properties (b, h, etc) on shell
startup, which caused a ProxyCommandError if m1n1 is not recent enough.

Signed-off-by: Vincent Duvert <vincent@duvert.net>
This commit is contained in:
Vincent Duvert 2021-06-05 10:16:03 +02:00 committed by Hector Martin
parent 4b5c016368
commit 1a95a9fc17

View file

@ -65,13 +65,19 @@ def run_shell(locals, msg=None, exitmsg=None):
if "utils" in locals and "u" not in locals:
locals["u"] = locals["utils"]
for obj in ("iface", "p", "u"):
if obj in locals:
for attr in dir(locals[obj]):
if attr not in locals:
v = getattr(locals[obj], attr)
if callable(v):
locals[attr] = v
for obj_name in ("iface", "p", "u"):
obj = locals.get(obj_name)
obj_class = type(obj)
if obj is None:
continue
for attr in dir(obj_class):
if attr in locals or attr.startswith('_'):
continue
member = getattr(obj_class, attr)
if callable(member) and not isinstance(member, property):
locals[attr] = getattr(obj, attr)
for attr in dir(sysreg):
locals[attr] = getattr(sysreg, attr)