-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #4956: autodoc: Failed to extract document from a subclass of the class on mocked module #4995
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
# type: (Any, Any) -> Any | ||
if len(args) == 3 and isinstance(args[1], tuple) and args[1][-1].__class__ is cls: | ||
# subclassing MockObject | ||
return type(args[0], (_MockObject,), args[2], **kwargs) # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
confirmed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've investigated for py2 error.
sphinx/ext/autodoc/importer.py
Outdated
# subclassing MockObject | ||
return type(args[0], (_MockObject,), args[2], **kwargs) # type: ignore | ||
else: | ||
return super().__new__(cls) # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not works with py2. Is super(M, cls)
correct?
return super(M, cls).__new__(cls) # type: ignore
test.py
from __future__ import print_function
class M(object):
def __new__(cls, *args, **kwargs):
print('new =>', cls, args, kwargs)
if len(args) == 3 and isinstance(args[1], tuple) and args[1][-1].__class__ is cls:
# subclassing MockObject
return type(args[0], (M,), args[2], **kwargs) # type: ignore
else:
return super(M, cls).__new__(cls) # type: ignore
t1 = 'm = M(1, b=2)'
print('exec:', t1); exec(t1)
print('subclassing M')
class F(M):
def __init__(self, a, b=0):
self.a = a
self.b = b
t2 = 'f = F(1, b=2)'
print('exec:', t2); exec(t2)
print('subclassing m')
class X(m):
def __init__(self, a, b=0):
self.a = a
self.b = b
t3 = 'x = X(1, b=2)'
print('exec:', t3); exec(t3)
run with py3
$ python3 test.py
exec: m = M(1, b=2)
new => <class '__main__.M'> (1,) {'b': 2}
subclassing M
exec: f = F(1, b=2)
new => <class '__main__.F'> (1,) {'b': 2}
subclassing m
new => <class '__main__.M'> ('X', (<__main__.M object at 0x1013b4400>,), {'__module__': '__main__', '__qualname__': 'X', '__init__': <function X.__init__ at 0x1013a98c8>}) {}
exec: x = X(1, b=2)
new => <class '__main__.X'> (1,) {'b': 2}
run with py2
$ python2 test.py
exec: m = M(1, b=2)
new => <class '__main__.M'> (1,) {'b': 2}
subclassing M
exec: f = F(1, b=2)
new => <class '__main__.F'> (1,) {'b': 2}
subclassing m
new => <class '__main__.M'> ('X', (<__main__.M object at 0x102132c50>,), {'__module__': '__main__', '__init__': <function __init__ at 0x102135b18>}) {}
exec: x = X(1, b=2)
new => <class '__main__.X'> (1,) {'b': 2}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. I'd forgotten the usage of super()
in py2...
6126dab
to
72fbbc4
Compare
Codecov Report
@@ Coverage Diff @@
## 1.7 #4995 +/- ##
=========================================
+ Coverage 81.99% 82% +0.01%
=========================================
Files 282 288 +6
Lines 37681 38022 +341
Branches 5846 5901 +55
=========================================
+ Hits 30895 31179 +284
- Misses 5481 5529 +48
- Partials 1305 1314 +9
Continue to review full report at Codecov.
|
…ass of the class on mocked module
72fbbc4
to
3080d24
Compare
@@ -47,6 +55,10 @@ def __iter__(self): | |||
# type: () -> None | |||
pass | |||
|
|||
def __mro_entries__(self, bases): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this method for https://www.python.org/dev/peps/pep-0560/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!!
Thanks! |
Feature or Bugfix
Purpose