-
-
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
autodoc: fix detection of class methods implemented by extension modules #13200
base: master
Are you sure you want to change the base?
Conversation
Works. |
Btw, I'm not sure if this is something CPython wants to improve by adding some |
Can't you use CPython builtin classes (e.g. int) to test this? BTW, there is no "official" way to describe signatures for extensions. The gmp module (as many CPython builtins) uses funny notation in |
I can use built-in classes but I wanted some complex inheritance just in case. I guess I can write some tests with what I have already in hand though. |
IIRC, multiple inheritance does not work for statically defined types. |
Oh I see. Though, I thought about inheriting (in pure Python) from my custom built-in class just to check that we correctly pick up something written in C as well. What I didn't want to do is use a built-in whose signature rendering may change across versions for various reasons. It makes tests harder to maintain (something that usually happens for |
# Conflicts: # CHANGES.rst # sphinx/ext/autodoc/__init__.py
I agree with Sergey that using e.g. A |
Co-authored-by: Adam Turner <[email protected]>
for basecls in getmro(cls): | ||
meth = basecls.__dict__.get(name, sentinel) | ||
if meth is not sentinel: | ||
return is_builtin_classmethod(meth) |
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.
Does this still need to recurse? I'd prefer being explicit here (even if duplicative):
return is_builtin_classmethod(meth) | |
return is_classmethod_descriptor(obj, cls, name) or ( | |
isbuiltin(obj) | |
and getattr(obj, '__self__', None) is not None | |
and isclass(obj.__self__) | |
) |
Closes #13188.
cc @skirpichev
@AA-Turner do we have tests for this? I tested it locally but I'm not sure we're building a C extension module in Sphinx to test this.