Repository navigation
Conversation
b9e28bc to
692a0b3
Compare
Codecov Report
@@ Coverage Diff @@
## master #5215 +/- ##
==========================================
+ Coverage 82.26% 82.28% +0.01%
==========================================
Files 302 302
Lines 39864 39961 +97
Branches 6153 6163 +10
==========================================
+ Hits 32794 32880 +86
- Misses 5727 5734 +7
- Partials 1343 1347 +4
Continue to review full report at Codecov.
|
|
As discussed in #4076, it would be better to enhance Since 1.8, Sphinx provides sphinx/sphinx/builders/html.py Lines 1605 to 1620 in 8ddca8c |
|
I just made #5223 for better testing (I'll merge it soon). I hope this helps this case. |
|
I didn't like the idea of overloading But I'm happy to follow your suggestion of using the converter function with the original option name. |
|
OMG, I just made #5277 as an alternative of this PR. Okay, let's discuss what is the best way to configure the default settings. I'll reconsider this later (It's time to sleep in japan 😄 ). @shimizukawa Please let me know your opinion. |
f14c54c to
73b93f2
Compare
|
I've made the changes to use I've added a load of tests for this, partly because the different combinations of options can be quite surprising. I found testing the diff between option on/off was the best for showing what the full effect is of each of the options/values. |
33a83a2 to
0c344b1
Compare
|
+1 for |
|
Okay, let's make it an alias of |
| from docutils.utils import Reporter # NOQA | ||
| from sphinx.application import Sphinx # NOQA | ||
| from sphinx.config import Config # NOQA | ||
| from sphinx.config import Config # NOQA |
|
|
||
| # with :special-members: | ||
| # Note that :members: must be *on* for :special-members: to work. | ||
| # TODO Is this a bug? |
There was a problem hiding this comment.
AFAIK, it's well-known behavior.
There was a problem hiding this comment.
removed TODO comment
|
|
||
|
|
||
| @pytest.mark.sphinx('html', testroot='ext-autodoc') | ||
| @pytest.mark.parametrize('target, options, expected_diff', [ |
There was a problem hiding this comment.
I feel this parameterized test is hard to understand...
Could you change this to simple testcases?
In addition, is doing diff important for this case? We've already done testing for each options. So I think the main purpose of this case is autodoc_default_flags modifies the options of each autodoc results.
There was a problem hiding this comment.
Done. I found the diffs useful for myself as I wasn't completely familiar with what each option did but, as you say, there are tests for this already. I've left the tests quite verbose but they don't use parametrize or look at the diffs.
Setting mutable types as default arguments is bad practice because the value is only initialised once. This means that defaults arguments of lists and dictionaries which are modified during code execution *stay* modified between calls. In this case, the `options` dictionary accumulated options as more and more test cases were executed. Without this change, the tests added in the next commit do not pass. See: https://stackoverflow.com/questions/1132941/least-astonishment-and-the-mutable-default-argument
Previously, users could specify a *list* of flags in their config files. The flags were directive names that would otherwise be present in the .rst files. However, as a list, it was not possible to specify values to those flags, which *is* possible in .rst files. For example, in .rst you could say :special-members: __init__, __iter__ And this would cause autodoc to generate documents for these methods that it would otherwise ignore. This commit changes the config option to instead accept a dictionary. This is a dictionary whose keys can contain the same flag-names as before, but whose values can contain the arguments as seen in .rst files. The old list is still supported, for backwards compatibility, but the data is transformed into a dictionary when the user's config is loaded.
As the previous commit explains, it is now possible to specify arguments to the global options in config files. This means that we can now include the `exclude-members` option in this global configuration. Previously, there was no point including this option because it makes no sense without arguments. Including this option means users have the flexibility of explicitly including which special methods they want using (e.g.): :special-members: __init__, __iter__ or explicitly excluding which special-members (or other members) they want using (e.g.): :exclude-members: __weakref__, __hash__
0c344b1 to
f196a92
Compare
|
Re. future work about making an alias for the option so its name makes more sense, could I suggest as well that the accepted types for the dict is more tightly defined. For example,
Just some thoughts I've had. :) |
|
Just merged! |
Subject: Set global default values for directives in config
Feature or Bugfix
Purpose
:special-members: __init__, __iter__. In config, you can set this flag, but only to include all special members, by including it in a listautodoc_default_flags. This PR make it so you can set the same values in global config as you can individually in RST files.Detail
test_autodocto work for me, becauseautodoc.directives.process_documenter_optionswants aoptionsobject which in the unit tests is mocked to aStruct, which doesn't work withprocess_documenter_options.in conf.py
Relates