Skip to content

Commit

Permalink
deal with objects that use AttributeError to "remove" fields
Browse files Browse the repository at this point in the history
  • Loading branch information
marinuso committed Aug 24, 2017
1 parent 620d6de commit dc09a38
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
7 changes: 6 additions & 1 deletion pynapl/ObjectWrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ def items(self):

for attr in dir(obj):

item = getattr(obj, attr)
try:
item = getattr(obj, attr)
if hasattr(item,'__call__'):
fn.append(attr)
else:
Expand All @@ -95,6 +95,11 @@ def items(self):
# ImportError and ignore it. If something could not be imported,
# it is simply not included in the list of attributes.
pass
except AttributeError:
# Some objects claim to have attributes (via `dir`), but then raise
# AttributeError when you actually try to access them. These are
# also ignored.
pass

return classname, va, fn

Expand Down
14 changes: 10 additions & 4 deletions pynapl/Py.dyalog
Original file line number Diff line number Diff line change
Expand Up @@ -1122,15 +1122,21 @@
Import a Python module and return it as an APL object
{obj}Import module
:Access Public
Exec'import ',module
objEval module
:Trap 0 1000
Exec'import ',module
objEval module
:Else ⎕SIGNAL('EN'(⎕DMX.EN))('Message'(⎕DMX.Message))
:EndTrap

Import from
{obj}ImportFrom (module child)
:Access Public
Exec'from ',module,' import ',child
objEval child
:Trap 0 1000
Exec'from ',module,' import ',child
objEval child
:Else ⎕SIGNAL('EN'(⎕DMX.EN))('Message'(⎕DMX.Message))
:EndTrap

expose a Python function as a monadic APL "function" (using a namespace)
Expand Down

0 comments on commit dc09a38

Please sign in to comment.