mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge branch '1.7-release' into use_flake8-import-order
This commit is contained in:
commit
6926a3ed91
1
CHANGES
1
CHANGES
@ -25,6 +25,7 @@ Bugs fixed
|
||||
* #4415: autodoc classifies inherited staticmethods as regular methods
|
||||
* #4472: DOCUMENTATION_OPTIONS is not defined
|
||||
* #4491: autodoc: prefer _MockImporter over other importers in sys.meta_path
|
||||
* #4490: autodoc: type annotation is broken with python 3.7.0a4+
|
||||
|
||||
Testing
|
||||
--------
|
||||
|
@ -36,6 +36,10 @@ exclude = .git,.tox,.venv,tests/*,build/*,doc/_build/*,sphinx/search/*,sphinx/py
|
||||
application-import-names = sphinx
|
||||
import-order-style = smarkets
|
||||
|
||||
[flake8:local-plugins]
|
||||
extension =
|
||||
X101 = utils.checks:sphinx_has_header
|
||||
|
||||
[mypy]
|
||||
python_version = 2.7
|
||||
show_column_numbers = True
|
||||
|
13
setup.py
13
setup.py
@ -15,7 +15,7 @@ if sys.version_info < (2, 7) or (3, 0) <= sys.version_info < (3, 4):
|
||||
print('ERROR: Sphinx requires at least Python 2.7 or 3.4 to run.')
|
||||
sys.exit(1)
|
||||
|
||||
requires = [
|
||||
install_requires = [
|
||||
'six>=1.5',
|
||||
'Jinja2>=2.3',
|
||||
'Pygments>=2.0',
|
||||
@ -47,7 +47,7 @@ extras_require = {
|
||||
'pytest',
|
||||
'pytest-cov',
|
||||
'html5lib',
|
||||
'flake8',
|
||||
'flake8>=3.5.0',
|
||||
'flake8-import-order',
|
||||
],
|
||||
'test:python_version<"3"': [
|
||||
@ -227,15 +227,8 @@ setup(
|
||||
'distutils.commands': [
|
||||
'build_sphinx = sphinx.setup_command:BuildDoc',
|
||||
],
|
||||
# consider moving this to 'flake8:local-plugins' once flake8 3.5.0 is
|
||||
# in the wild:
|
||||
# http://flake8.pycqa.org/en/latest/user/configuration.html\
|
||||
# #using-local-plugins
|
||||
'flake8.extension': [
|
||||
'X101 = utils.checks:sphinx_has_header',
|
||||
],
|
||||
},
|
||||
install_requires=requires,
|
||||
install_requires=install_requires,
|
||||
extras_require=extras_require,
|
||||
cmdclass=cmdclass,
|
||||
)
|
||||
|
@ -431,6 +431,55 @@ class Signature(object):
|
||||
|
||||
Displaying complex types from ``typing`` relies on its private API.
|
||||
"""
|
||||
if sys.version_info >= (3, 7): # py37+
|
||||
return self.format_annotation_new(annotation)
|
||||
else:
|
||||
return self.format_annotation_old(annotation)
|
||||
|
||||
def format_annotation_new(self, annotation):
|
||||
# type: (Any) -> str
|
||||
"""format_annotation() for py37+"""
|
||||
module = getattr(annotation, '__module__', None)
|
||||
if isinstance(annotation, string_types):
|
||||
return annotation # type: ignore
|
||||
elif isinstance(annotation, typing.TypeVar): # type: ignore
|
||||
return annotation.__name__
|
||||
elif not annotation:
|
||||
return repr(annotation)
|
||||
elif module == 'builtins':
|
||||
return annotation.__qualname__
|
||||
elif annotation is Ellipsis:
|
||||
return '...'
|
||||
|
||||
if module == 'typing':
|
||||
if getattr(annotation, '_name', None):
|
||||
qualname = annotation._name
|
||||
elif getattr(annotation, '__qualname__', None):
|
||||
qualname = annotation.__qualname__
|
||||
else:
|
||||
qualname = self.format_annotation(annotation.__origin__) # ex. Union
|
||||
elif hasattr(annotation, '__qualname__'):
|
||||
qualname = '%s.%s' % (module, annotation.__qualname__)
|
||||
else:
|
||||
qualname = repr(annotation)
|
||||
|
||||
if getattr(annotation, '__args__', None):
|
||||
if qualname == 'Union':
|
||||
args = ', '.join(self.format_annotation(a) for a in annotation.__args__)
|
||||
return '%s[%s]' % (qualname, args)
|
||||
elif qualname == 'Callable':
|
||||
args = ', '.join(self.format_annotation(a) for a in annotation.__args__[:-1])
|
||||
returns = self.format_annotation(annotation.__args__[-1])
|
||||
return '%s[[%s], %s]' % (qualname, args, returns)
|
||||
else:
|
||||
args = ', '.join(self.format_annotation(a) for a in annotation.__args__)
|
||||
return '%s[%s]' % (qualname, args)
|
||||
|
||||
return qualname
|
||||
|
||||
def format_annotation_old(self, annotation):
|
||||
# type: (Any) -> str
|
||||
"""format_annotation() for py36 or below"""
|
||||
if isinstance(annotation, string_types):
|
||||
return annotation # type: ignore
|
||||
if isinstance(annotation, typing.TypeVar): # type: ignore
|
||||
|
@ -215,12 +215,7 @@ def test_Signature_annotations():
|
||||
|
||||
# TypeVars and generic types with TypeVars
|
||||
sig = inspect.Signature(f2).format_args()
|
||||
if sys.version_info < (3, 7):
|
||||
sig == ('(x: typing.List[T], y: typing.List[T_co], z: T) -> '
|
||||
'typing.List[T_contra]')
|
||||
else:
|
||||
sig == ('(x: typing.List[~T], y: typing.List[+T_co], z: T) -> '
|
||||
'typing.List[-T_contra]')
|
||||
assert sig == '(x: List[T], y: List[T_co], z: T) -> List[T_contra]'
|
||||
|
||||
# Union types
|
||||
sig = inspect.Signature(f3).format_args()
|
||||
|
Loading…
Reference in New Issue
Block a user