Merge pull request #5998 from tk0miya/5995_mock_conflicts_with_metaclass

Fix #5995: autodoc: autodoc_mock_imports conflict with metaclass
This commit is contained in:
Takeshi KOMIYA 2019-02-03 17:01:23 +09:00 committed by GitHub
commit 6b3244d679
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 1 deletions

View File

@ -33,6 +33,7 @@ Bugs fixed
* #5960: LaTeX: modified PDF layout since September 2018 TeXLive update of * #5960: LaTeX: modified PDF layout since September 2018 TeXLive update of
:file:`parskip.sty` :file:`parskip.sty`
* #5958: versionadded directive causes crash with Python 3.5.0 * #5958: versionadded directive causes crash with Python 3.5.0
* #5995: autodoc: autodoc_mock_imports conflict with metaclass on Python 3.7
Testing Testing
-------- --------

View File

@ -57,7 +57,7 @@ class _MockObject(object):
def __mro_entries__(self, bases): def __mro_entries__(self, bases):
# type: (Tuple) -> Tuple # type: (Tuple) -> Tuple
return bases return (self.__class__,)
def __getitem__(self, key): def __getitem__(self, key):
# type: (str) -> _MockObject # type: (str) -> _MockObject

View File

@ -9,6 +9,11 @@
:license: BSD, see LICENSE for details. :license: BSD, see LICENSE for details.
""" """
import abc
import sys
import pytest
from sphinx.ext.autodoc.importer import _MockObject from sphinx.ext.autodoc.importer import _MockObject
@ -29,3 +34,21 @@ def test_MockObject():
assert isinstance(obj, SubClass) assert isinstance(obj, SubClass)
assert obj.method() == "string" assert obj.method() == "string"
assert isinstance(obj.other_method(), SubClass) assert isinstance(obj.other_method(), SubClass)
@pytest.mark.skipif(sys.version_info < (3, 7), reason='Only for py37 or above')
def test_abc_MockObject():
mock = _MockObject()
class Base:
@abc.abstractmethod
def __init__(self):
pass
class Derived(Base, mock.SubClass):
pass
obj = Derived()
assert isinstance(obj, Base)
assert isinstance(obj, _MockObject)
assert isinstance(obj.some_method(), Derived)