Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Simplify docstring.py.#9172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion.appveyor.yml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -86,7 +86,7 @@ install:
mock sphinx pandas
- activate test-environment
- echo %PYTHON_VERSION% %TARGET_ARCH%
- if %PYTHON_VERSION% == 2.7 conda install -q backports.functools_lru_cache
- if %PYTHON_VERSION% == 2.7 conda install -q backports.functools_lru_cache funcsigs
# pytest-cov>=2.3.1 due to https://github.com/pytest-dev/pytest-cov/issues/124
- pip install -q pytest "pytest-cov>=2.3.1" pytest-rerunfailures pytest-timeout

Expand Down
3 changes: 2 additions & 1 deletionINSTALL.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -187,6 +187,7 @@ Matplotlib requires a large number of dependencies:
* `six <https://pypi.python.org/pypi/six>`_
* `backports.functools_lru_cache <https://pypi.python.org/pypi/backports.functools_lru_cache>`_
(for Python 2.7 only)
* `funcsigs <https://pypi.python.org/pypi/funcsigs>`_ (for Python 2.7 only)
* `subprocess32 <https://pypi.python.org/pypi/subprocess32/>`_ (for Python
2.7 only, on Linux and macOS only)

Expand DownExpand Up@@ -332,7 +333,7 @@ without fiddling with environment variables::
# this package is only available in the conda-forge channel
conda install -c conda-forge msinttypes
# for Python 2.7
conda install -c conda-forge backports.functools_lru_cache
conda install -c conda-forge backports.functools_lru_cache funcsigs

# copy the libs which have "wrong" names
set LIBRARY_LIB=%CONDA_DEFAULT_ENV%\Library\lib
Expand Down
2 changes: 1 addition & 1 deletionbuild_alllocal.cmd
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,7 +7,7 @@
:: # this package is only available in the conda-forge channel
:: conda install -c conda-forge msinttypes
:: if you build on py2.7:
:: conda install -c conda-forge backports.functools_lru_cache
:: conda install -c conda-forge backports.functools_lru_cache funcsigs

set TARGET=bdist_wheel
IF [%1]==[] (
Expand Down
2 changes: 2 additions & 0 deletionsci/conda_recipe/meta.yaml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -40,6 +40,7 @@ requirements:
- pyqt # [not osx]
- tk 8.5* # [linux]
- backports.functools_lru_cache # [py2k]
- funcsigs # [py2k]

run:
- python
Expand All@@ -55,6 +56,7 @@ requirements:
- pyqt # [not osx]
- tk 8.5* # [linux and win]
- backports.functools_lru_cache # [py2k]
- funcsigs # [py2k]

test:
imports:
Expand Down
2 changes: 1 addition & 1 deletionlib/matplotlib/axes/_axes.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -230,7 +230,7 @@ def get_ylabel(self):

def set_ylabel(self, ylabel, fontdict=None, labelpad=None, **kwargs):
"""
Set the label for the yaxis
Set the label for the yaxis.

Parameters
----------
Expand Down
63 changes: 28 additions & 35 deletionslib/matplotlib/axes/_base.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1488,45 +1488,40 @@ def apply_aspect(self, position=None):
self.set_xbound((x0, x1))

def axis(self, *v, **kwargs):
"""Set axis properties.
"""Convenience method to get or set axis properties.

Valid signatures::

xmin, xmax, ymin, ymax = axis()
xmin, xmax, ymin, ymax = axis(list_arg)
xmin, xmax, ymin, ymax = axis(string_arg)
xmin, xmax, ymin, ymax = axis(**kwargs)
xmin, xmax, ymin, ymax = axis(*, emit=True)
xmin, xmax, ymin, ymax = axis(_string_arg_, *, emit=True)
xmin, xmax, ymin, ymax = axis([xmin, ymin, xmax, ymax], *, emit=True)

Parameters
----------
v : list of float or {'on', 'off', 'equal', 'tight', 'scaled',\
'normal', 'auto', 'image', 'square'}
Optional positional argument

Axis data limits set from a list; or a command relating to axes:

========== ================================================
Value Description
========== ================================================
'on' Toggle axis lines and labels on
'off' Toggle axis lines and labels off
'equal' Equal scaling by changing limits
'scaled' Equal scaling by changing box dimensions
'tight' Limits set such that all data is shown
'auto' Automatic scaling, fill rectangle with data
'normal' Same as 'auto'; deprecated
'image' 'scaled' with axis limits equal to data limits
'square' Square plot; similar to 'scaled', but initially\
forcing xmax-xmin = ymax-ymin
========== ================================================

emit : bool, optional
Passed to set_{x,y}lim functions, if observers
are notified of axis limit change
_string_arg_ : str, optional

The following values are allowed:

========== =======================================================
Value Description
========== =======================================================
'on' Toggle axis lines and labels on
'off' Toggle axis lines and labels off
'equal' Equal scaling by changing limits
'scaled' Equal scaling by changing box dimensions
'tight' Limits set such that all data is shown
'auto' Automatic scaling, fill rectangle with data
'image' 'scaled' with axis limits equal to data limits
'square' Square plot; similar to 'scaled', but initially forcing
``xmax-xmin = ymax-ymin``
========== =======================================================

xmin, ymin, xmax, ymax : float, optional
The axis limits to be set

emit : bool, optional
Whether observers are notified of axes limit changes.

Returns
-------
xmin, xmax, ymin, ymax : float
Expand All@@ -1547,17 +1542,15 @@ def axis(self, *v, **kwargs):
self.set_axis_on()
elif s == 'off':
self.set_axis_off()
elif s in ('equal', 'tight', 'scaled', 'normal',
'auto', 'image', 'square'):
elif s in ['equal', 'tight', 'scaled', 'auto', 'image', 'square']:
self.set_autoscale_on(True)
self.set_aspect('auto')
self.autoscale_view(tight=False)
# self.apply_aspect()
if s == 'equal':
self.set_aspect('equal', adjustable='datalim')
elif s == 'scaled':
self.set_aspect('equal', adjustable='box', anchor='C')
self.set_autoscale_on(False) # Req. by Mark Bakker
self.set_autoscale_on(False)
elif s == 'tight':
self.autoscale_view(tight=True)
self.set_autoscale_on(False)
Expand DownExpand Up@@ -2950,7 +2943,7 @@ def get_xscale(self):

def set_xscale(self, value, **kwargs):
"""
Set the x-axis scale
Set the x-axis scale.

Parameters
----------
Expand DownExpand Up@@ -3257,7 +3250,7 @@ def get_yscale(self):

def set_yscale(self, value, **kwargs):
"""
Set the y-axis scale
Set the y-axis scale.

Parameters
----------
Expand Down
101 changes: 56 additions & 45 deletionslib/matplotlib/docstring.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,52 +4,53 @@
import six

from matplotlib import cbook
import sys
import types


class Substitution(object):
"""
A decorator to take a function's docstring and perform string
substitution on it.
"""A decorator that performs %-substitution on an object's docstring.

This decorator should be robust even iffunc.__doc__ is None
(for example,if -OO was passed to the interpreter)
This decorator should be robust even ifobj.__doc__ is None (for example,
if -OO was passed to the interpreter)

Usage: construct a docstring.Substitution with a sequence or
dictionarysuitable for performing substitution; then
decorate a suitable functionwith the constructed object. e.g.
Usage: construct a docstring.Substitution with a sequence or dictionary
suitable for performing substitution; then decorate a suitable function
with the constructed object, e.g.::

sub_author_name = Substitution(author='Jason')
sub_author_name = Substitution(author='Jason')

@sub_author_name
def some_function(x):
"%(author)s wrote this function"
@sub_author_name
def some_function(x):
"%(author)s wrote this function"

# note that some_function.__doc__ is now "Jason wrote this function"
# note that some_function.__doc__ is now "Jason wrote this function"

One can also use positional arguments.
One can also use positional arguments::

sub_first_last_names = Substitution('Edgar Allen', 'Poe')
sub_first_last_names = Substitution('Edgar Allen', 'Poe')

@sub_first_last_names
def some_function(x):
"%s %s wrote the Raven"
@sub_first_last_names
def some_function(x):
"%s %s wrote the Raven"
"""
def __init__(self, *args, **kwargs):
assert not (len(args) andlen(kwargs)), \
"Only positional or keyword args are allowed"
ifargs and kwargs:
raise ValueError("Only positional or keyword args are allowed")
self.params = args or kwargs

def __call__(self, func):
func.__doc__ = func.__doc__ and func.__doc__ % self.params
if func.__doc__:
if six.PY2:
getattr(func, "im_func", func).__doc__ %= self.params
else:
func.__doc__ %= self.params
return func

def update(self, *args, **kwargs):
"Assume self.params is a dict and update it with supplied args"
"""Assume self.params is a dict and update it with supplied args."""
self.params.update(*args, **kwargs)

@classmethod
@cbook.deprecated("2.2")
def from_params(cls, params):
"""
In the case where the params is a mutable sequence (list or
Expand All@@ -62,6 +63,7 @@ def from_params(cls, params):
return result


@cbook.deprecated("2.2")
class Appender(object):
"""
A function decorator that will append an addendum to the docstring
Expand All@@ -86,43 +88,52 @@ def __init__(self, addendum, join=''):
self.join = join

def __call__(self, func):
docitems = [func.__doc__, self.addendum]
func.__doc__ =func.__doc__and self.join.join(docitems)
iffunc.__doc__:
func.__doc__= self.join.join([func.__doc__, self.addendum])
return func


@cbook.deprecated("2.2")
def dedent(func):
"Dedent a docstring (if present)"
func.__doc__ = func.__doc__ and cbook.dedent(func.__doc__)
"""Dedent a docstring (if present)."""
if func.__doc__:
if six.PY2:
getattr(func, "im_func", func).__doc__ = cbook.dedent(func.__doc__)
else:
func.__doc__ = cbook.dedent(func.__doc__)
return func


@cbook.deprecated("2.2")
def copy(source):
"Copy adocstring fromanother sourcefunction(if present)"
defdo_copy(target):
"""A decorator that copies thedocstring fromthe source (if present)."""
defdecorator(target):
if source.__doc__:
target.__doc__ = source.__doc__
return target
returndo_copy
returndecorator

#create a decorator that will house the various documentation that
# is reusedthroughoutmatplotlib
#Create a decorator that will house the various documentation that is reused
# throughoutMatplotlib.
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 not six.PY3:
func = func.im_func
return interpd(dedent(func))
"""Decorator that dedents and interpolates an object's docstring.
"""
if func.__doc__:
if six.PY2:
getattr(func, "im_func", func).__doc__ = cbook.dedent(func.__doc__)
else:
func.__doc__ = cbook.dedent(func.__doc__)
return interpd(func)


@cbook.deprecated("2.2")
def copy_dedent(source):
"""A decorator that will copy the docstring from the source and
then dedent it"""
# note the following is ugly because "Python is not a functional
# language" - GVR. Perhaps one day, functools.compose will exist.
# or perhaps not.
# http://mail.python.org/pipermail/patches/2007-February/021687.html
return lambda target: dedent(copy(source)(target))
"""A decorator that copies the dedented docstring from the source."""
def decorator(func):
if source.__doc__:
dedent(source)
return func
return decorator
Loading

[8]ページ先頭

©2009-2025 Movatter.jp