-
-
Notifications
You must be signed in to change notification settings - Fork 162
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
Cope with unexpected signature #277
base: main
Are you sure you want to change the base?
Conversation
Fixes a regression in numpydoc v1.1.0 compared to v1.0.0 which did not have the _clean_text_signature function.
Codecov Report
@@ Coverage Diff @@
## master #277 +/- ##
==========================================
+ Coverage 93.15% 93.17% +0.01%
==========================================
Files 7 7
Lines 1257 1260 +3
==========================================
+ Hits 1171 1174 +3
Misses 86 86 |
User defined classes can do strange things.
@peterjc I know you said you don't have a minimal test case, but is there a link to the full CI failure somewhere? It'd be nice to be able to see the full traceback (if it exists). I looked for it in the CI logs on biopython/biopython#3022 but didn't see anything docs/sphinx related |
Example from TravisCI with minimal clues: https://travis-ci.org/github/biopython/biopython/jobs/704617159 From running locally on macOS with more verbose settings and the following for debuging: def _clean_text_signature(sig):
if sig is None:
return None
start_pattern = re.compile(r"^[^(]*\(")
try:
start, end = start_pattern.search(sig).span()
except TypeError:
raise TypeError("Got %r of type %s in _clean_text_signature" % (sig, type(sig))) from None
start_sig = sig[start:end]
sig = sig[end:-1]
sig = re.sub(r'^\$(self|module|type)(,\s|$)','' , sig, count=1)
sig = re.sub(r'(^|(?<=,\s))/,\s\*', '*', sig, count=1)
return start_sig + sig + ')' Got:
|
This will possibly also fix #276 👍 |
Yes, I think this would fix #276 too - hopefully that might give a more useful test case? |
@peterjc What is the value of It might be better to convert the if isinstance(sig, bytes):
sig = sig.decode() |
I failed to work out what exactly the object was in my case, something created dynamically was my hunch. Handling bytes explicitly certainly wouldn't hurt though. |
No, it's not bytes, it's a class, so I think we should try `sig = str(sig)`
|
That sounds good - do you want me to try that, or can I leave this with you? |
I experimented with this for a bit. It looks like the troublesome problem is that I found editing (I only added the check if obj is a def mangle_signature(app, what, name, obj, options, sig, retann):
# Do not try to inspect classes that don't define `__init__`
if (inspect.isclass(obj) and
(not hasattr(obj, '__init__') or
'initializes x; see ' in pydoc.getdoc(obj.__init__))):
return '', ''
if isinstance(obj, ModuleType):
return
if not (isinstance(obj, Callable) or
hasattr(obj, '__argspec_is_invalid_')):
return
if not hasattr(obj, '__doc__'):
return
doc = get_doc_object(obj, config={'show_class_members': False})
sig = (doc['Signature']
or _clean_text_signature(getattr(obj, '__text_signature__', None)))
if sig:
sig = re.sub("^[^(]*", "", sig)
return sig, '' |
Do classes without |
Following testing on biopython/biopython#3045 it seems we only see the problem with the restriction code when using Does mock do something predictable to the signatures? |
Mock could be the right track to fix the problem. We use |
Fixes a regression in numpydoc v1.1.0 compared to v1.0.0 which did not have the
_clean_text_signature
function, manifested as:Handler <function mangle_signature at 0x7f8ae571b620> for event 'autodoc-process-signature' threw an exception
I don't have a minimal test case, something strange in Biopython's
Bio.Restriction
triggered this - a module which creates a vast number of classes which we currently try to exclude from the Sphinx API docs via mocking the import. See biopython/biopython#3024