Skip to content

Commit

Permalink
Merge pull request matplotlib#2200 from NelleV/PEP8_docstring
Browse files Browse the repository at this point in the history
ENH docstring is now PEP8
  • Loading branch information
mdboom committed Jul 4, 2013
2 parents d03f053 + 4a1dc52 commit 64cc341
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/matplotlib/docstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
import types


class Substitution(object):
"""
A decorator to take a function's docstring and perform string
Expand Down Expand Up @@ -32,7 +33,8 @@ def some_function(x):
"%s %s wrote the Raven"
"""
def __init__(self, *args, **kwargs):
assert not (args and kwargs), "Only positional or keyword args are allowed"
assert (not (args and kwargs),
"Only positional or keyword args are allowed")
self.params = args or kwargs

def __call__(self, func):
Expand All @@ -46,15 +48,16 @@ def update(self, *args, **kwargs):
@classmethod
def from_params(cls, params):
"""
In the case where the params is a mutable sequence (list or dictionary)
and it may change before this class is called, one may explicitly use
a reference to the params rather than using *args or **kwargs which will
copy the values and not reference them.
In the case where the params is a mutable sequence (list or
dictionary) and it may change before this class is called, one may
explicitly use a reference to the params rather than using *args or
**kwargs which will copy the values and not reference them.
"""
result = cls()
result.params = params
return result


class Appender(object):
"""
A function decorator that will append an addendum to the docstring
Expand Down Expand Up @@ -83,11 +86,13 @@ def __call__(self, func):
func.__doc__ = func.__doc__ and ''.join(docitems)
return func


def dedent(func):
"Dedent a docstring (if present)"
func.__doc__ = func.__doc__ and cbook.dedent(func.__doc__)
return func


def copy(source):
"Copy a docstring from another source function (if present)"
def do_copy(target):
Expand All @@ -100,13 +105,15 @@ def do_copy(target):
# is reused throughout matplotlib
interpd = Substitution()


def dedent_interpd(func):
"""A special case of the interpd that first performs a dedent on
the incoming docstring"""
if isinstance(func, types.MethodType) and sys.version_info[0] < 3:
func = func.im_func
return interpd(dedent(func))


def copy_dedent(source):
"""A decorator that will copy the docstring from the source and
then dedent it"""
Expand Down

0 comments on commit 64cc341

Please sign in to comment.