Skip to content

Commit

Permalink
Merge pull request #48 from IntelPython/feature/print-behavior
Browse files Browse the repository at this point in the history
Feature/print behavior
  • Loading branch information
fschlimb authored Feb 6, 2019
2 parents 642dac2 + e1c7051 commit 867f09f
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions generator/wrapper_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,28 @@ def my_procid():
x = [x.values]
return new data_or_file(<PyObject *>x)
def _str(instance, properties):
result = ''
for p in properties:
prop = getattr(instance, p, None)
tail = ''
if isinstance(prop, np.ndarray):
result += p + ': array('
tail = ',\\n dtype={}, shape={})'.format(prop.dtype,
prop.shape)
elif isinstance(prop, dict):
result += p + ': dict, len={}'.format(len(prop))
else:
result += p + ': '
value = '\\n '.join(str(prop).splitlines())
if '\\n' in value or isinstance(prop, np.ndarray):
result += '\\n '
result += value
result += tail
result += '\\n\\n'
return result[:-2]
'''

###############################################################################
Expand Down Expand Up @@ -268,6 +290,8 @@ def __dealloc__(self):
def __init__(self, int64_t ptr=0):
self.c_ptr = <{{class_type|flat}}>ptr
def __str__(self):
return _str(self, [{% for m in enum_gets+named_gets %}'{{m[1]}}',{% endfor %}])
{% for m in enum_gets+named_gets %}
{% set rtype = m[2]|d2cy(False) if m in enum_gets else m[0]|d2cy(False) %}
Expand Down

0 comments on commit 867f09f

Please sign in to comment.