[New-bugs-announce] [issue37102] Automatically dedent docstring constants by default

Gregory P. Smith report at bugs.python.org
Thu May 30 14:00:00 EDT 2019


New submission from Gregory P. Smith <greg at krypto.org>:

I'm spawning this issue of as a separate feature from https://bugs.python.org/issue36906 (adding string dedent method and an optimization to do it at compile timer on constants).

It'd be great if docstrings were given a similar treatment.  Right now we carry the whitespace burden within the str constants for __doc__ stored in all code objects in the process.  This adds up.

This is not _quite_ the same as calling textwrap.dedent() or the upcoming str.dedent method on them at compile time.  We need to special case the first line of docstrings.  inspect.getdoc() is our library function that does this for us today.

Change of breaking things with this change?  not impossible, but extremely minor.  Something using docstrings as data _and_ depending on leading indentation whitespace preservation would not like this.  I am not aware of anything that would ever do that.

----------
components: Interpreter Core
messages: 343990
nosy: gregory.p.smith
priority: normal
severity: normal
status: open
title: Automatically dedent docstring constants by default
type: enhancement
versions: Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37102>
_______________________________________


More information about the New-bugs-announce mailing list