ENH: Include sharedoc function

This commit is contained in:
Ana Ruelas
2017-06-02 11:48:33 -04:00
parent 2d56d253fa
commit ff1c673a9d
3 changed files with 41 additions and 1 deletions
+21
View File
@@ -0,0 +1,21 @@
from zipline.testing import ZiplineTestCase
from zipline.utils.sharedoc import copydoc
class TestSharedoc(ZiplineTestCase):
def test_copydoc(self):
def original_docstring_function():
"""
My docstring brings the boys to the yard.
"""
pass
@copydoc(original_docstring_function)
def copied_docstring_function():
pass
self.assertEqual(
original_docstring_function.__doc__,
copied_docstring_function.__doc__
)
+1 -1
View File
@@ -12,7 +12,6 @@ from six import (
with_metaclass,
)
from numpy import array
from odo.utils import copydoc
from pandas import DataFrame, MultiIndex
from toolz import groupby, juxt
from toolz.curried.operator import getitem
@@ -30,6 +29,7 @@ from .term import AssetExists, InputDates, LoadableTerm
from zipline.utils.date_utils import compute_date_range_chunks
from zipline.utils.pandas_utils import categorical_df_concat
from zipline.utils.sharedoc import copydoc
class PipelineEngine(with_metaclass(ABCMeta)):
+19
View File
@@ -5,6 +5,7 @@ across different functions.
import re
from six import iteritems
from textwrap import dedent
from toolz import curry
PIPELINE_DOWNSAMPLING_FREQUENCY_DOC = dedent(
"""\
@@ -98,3 +99,21 @@ def templated_docstring(**docs):
f.__doc__ = format_docstring(f.__name__, f.__doc__, docs)
return f
return decorator
@curry
def copydoc(from_, to):
"""Copies the docstring from one function to another.
Parameters
----------
from_ : any
The object to copy the docstring from.
to : any
The object to copy the docstring to.
Returns
-------
to : any
``to`` with the docstring from ``from_``
"""
to.__doc__ = from_.__doc__
return to