Skip to content

Commit 1c0616a

Browse files
committed
Changed PyscriptBridge.__getattr__ to raise Attribute error for non-commands
1 parent 4902d1c commit 1c0616a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

cmd2/pyscript_bridge.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,10 @@ def __init__(self, cmd2_app):
250250
self.cmd_echo = False
251251

252252
def __getattr__(self, item: str):
253-
"""If attribute is a command, return a callable. Otherwise return the attribute."""
253+
"""
254+
Provide a way to call application commands via the PyscriptBridge
255+
ex: app.help()
256+
"""
254257
func = self._cmd2_app.cmd_func(item)
255258

256259
if func:
@@ -264,7 +267,8 @@ def wrap_func(args=''):
264267

265268
return wrap_func
266269
else:
267-
return getattr(self._cmd2_app, item)
270+
# item does not refer to a command
271+
raise AttributeError("'{}' object has no attribute '{}'".format(self._cmd2_app.pyscript_name, item))
268272

269273
def __dir__(self):
270274
"""Return a custom set of attribute names to match the available commands"""

0 commit comments

Comments
 (0)