Skip to content

append_doc method breaks with interpreter optimization on #270

@sevdog

Description

@sevdog

The CPython interpreter has an optimization flag -OO which discards assertions and docstrings.

def append_doc(value):
def _doc(func):
func.__doc__ = dedent(func.__doc__) + "\n" + value
return func
return _doc

The current implementation of append_doc method causes a TypeError if this optimization level is set, since the __doc__ attribute is None (cause it was not kept in the compiled module):

   File "/opt/venv/lib/python3.9/site-packages/pyexcel/_compact.py", line 90, in _doc
     func.__doc__ = dedent(func.__doc__) + "\n" + value         
   File "/usr/local/lib/python3.9/textwrap.py", line 430, in dedent                                                                                                
     text = _whitespace_only_re.sub('', text)         
 TypeError: expected string or bytes-like object

A solution could be this method to do nothing if func.__doc__ is None.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions