mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #4489 from tk0miya/1.7-release
workaround for typing module in py370a4+
This commit is contained in:
commit
376b6a597d
@ -15,7 +15,6 @@ import re
|
|||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import codecs
|
import codecs
|
||||||
import platform
|
|
||||||
from os import path
|
from os import path
|
||||||
import doctest
|
import doctest
|
||||||
|
|
||||||
@ -144,7 +143,8 @@ class TestDirective(Directive):
|
|||||||
if self.name == 'doctest' and 'pyversion' in self.options:
|
if self.name == 'doctest' and 'pyversion' in self.options:
|
||||||
try:
|
try:
|
||||||
spec = self.options['pyversion']
|
spec = self.options['pyversion']
|
||||||
if not is_allowed_version(spec, platform.python_version()):
|
python_version = '.'.join(str(v) for v in sys.version_info[:3])
|
||||||
|
if not is_allowed_version(spec, python_version):
|
||||||
flag = doctest.OPTIONFLAGS_BY_NAME['SKIP']
|
flag = doctest.OPTIONFLAGS_BY_NAME['SKIP']
|
||||||
node['options'][flag] = True # Skip the test
|
node['options'][flag] = True # Skip the test
|
||||||
except InvalidSpecifier:
|
except InvalidSpecifier:
|
||||||
|
@ -453,7 +453,8 @@ class Signature(object):
|
|||||||
|
|
||||||
if annotation.__module__ == 'builtins':
|
if annotation.__module__ == 'builtins':
|
||||||
return annotation.__qualname__ # type: ignore
|
return annotation.__qualname__ # type: ignore
|
||||||
elif isinstance(annotation, typing.GenericMeta):
|
elif (hasattr(typing, 'GenericMeta') and # for py36 or below
|
||||||
|
isinstance(annotation, typing.GenericMeta)):
|
||||||
# In Python 3.5.2+, all arguments are stored in __args__,
|
# In Python 3.5.2+, all arguments are stored in __args__,
|
||||||
# whereas __parameters__ only contains generic parameters.
|
# whereas __parameters__ only contains generic parameters.
|
||||||
#
|
#
|
||||||
@ -480,7 +481,8 @@ class Signature(object):
|
|||||||
if params is not None:
|
if params is not None:
|
||||||
param_str = ', '.join(self.format_annotation(p) for p in params)
|
param_str = ', '.join(self.format_annotation(p) for p in params)
|
||||||
return '%s[%s]' % (qualified_name, param_str)
|
return '%s[%s]' % (qualified_name, param_str)
|
||||||
elif (isinstance(annotation, typing.CallableMeta) and # type: ignore
|
elif (hasattr(typing, 'CallableMeta') and # for py36 or below
|
||||||
|
isinstance(annotation, typing.CallableMeta) and # type: ignore
|
||||||
getattr(annotation, '__args__', None) is not None and
|
getattr(annotation, '__args__', None) is not None and
|
||||||
hasattr(annotation, '__result__')):
|
hasattr(annotation, '__result__')):
|
||||||
# Skipped in the case of plain typing.Callable
|
# Skipped in the case of plain typing.Callable
|
||||||
@ -495,7 +497,8 @@ class Signature(object):
|
|||||||
return '%s[%s, %s]' % (qualified_name,
|
return '%s[%s, %s]' % (qualified_name,
|
||||||
args_str,
|
args_str,
|
||||||
self.format_annotation(annotation.__result__))
|
self.format_annotation(annotation.__result__))
|
||||||
elif (isinstance(annotation, typing.TupleMeta) and # type: ignore
|
elif (hasattr(typing, 'TupleMeta') and # for py36 or below
|
||||||
|
isinstance(annotation, typing.TupleMeta) and # type: ignore
|
||||||
hasattr(annotation, '__tuple_params__') and
|
hasattr(annotation, '__tuple_params__') and
|
||||||
hasattr(annotation, '__tuple_use_ellipsis__')):
|
hasattr(annotation, '__tuple_use_ellipsis__')):
|
||||||
params = annotation.__tuple_params__
|
params = annotation.__tuple_params__
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import errno
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@ -20,7 +21,7 @@ def has_binary(binary):
|
|||||||
try:
|
try:
|
||||||
subprocess.check_output([binary])
|
subprocess.check_output([binary])
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno == os.errno.ENOENT:
|
if e.errno == errno.ENOENT:
|
||||||
# handle file not found error.
|
# handle file not found error.
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
|
@ -215,7 +215,12 @@ def test_Signature_annotations():
|
|||||||
|
|
||||||
# TypeVars and generic types with TypeVars
|
# TypeVars and generic types with TypeVars
|
||||||
sig = inspect.Signature(f2).format_args()
|
sig = inspect.Signature(f2).format_args()
|
||||||
assert sig == '(x: List[T], y: List[T_co], z: T) -> List[T_contra]'
|
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]')
|
||||||
|
|
||||||
# Union types
|
# Union types
|
||||||
sig = inspect.Signature(f3).format_args()
|
sig = inspect.Signature(f3).format_args()
|
||||||
|
Loading…
Reference in New Issue
Block a user