Skip to content

Commit

Permalink
code-block: Handle 0 as numeric argument in :dedent:
Browse files Browse the repository at this point in the history
Due to how Python converts ints to bool the numeric argument ``0`` to
the :dedent: option of the code-block directive was handled like if no
argument was given to :dedent:.

Check properly for None in the options argument processing, so ``0`` is
treated as numeric argument to :dedent:.

Bug: sphinx-doc#9636
  • Loading branch information
latosha-maltba committed Sep 21, 2021
1 parent cf9b5b5 commit 3b46553
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -23,6 +23,7 @@ Bugs fixed
* #9644: autodoc: Crashed on getting source info from problematic object
* #9630: autosummary: Failed to build summary table if :confval:`primary_domain`
is not 'py'
* #9636: code-block: ``:dedent:`` handled numeric argument ``0`` like no argument was given

Testing
--------
Expand Down
2 changes: 1 addition & 1 deletion sphinx/directives/code.py
Expand Up @@ -57,7 +57,7 @@ def run(self) -> List[Node]:


def dedent_lines(lines: List[str], dedent: int, location: Tuple[str, int] = None) -> List[str]:
if not dedent:
if dedent is None:
return textwrap.dedent(''.join(lines)).splitlines(True)

if any(s[:dedent].strip() for s in lines):
Expand Down

0 comments on commit 3b46553

Please sign in to comment.