This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Miguel Amaral
Recipients Marco Sulla, Miguel Amaral, gregory.p.smith, josh.r, mbussonn, methane, pablogsal, remi.lapeyre, rhettinger, serhiy.storchaka, steven.daprano
Date 2020-04-03.10:54:09
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1585911249.79.0.778684644323.issue36906@roundup.psfhosted.org>
In-reply-to
Content
A related issue(which I believe has no topic in this forum yet) is substituting an expression that results in a multiline string into a multiline f-string while matching its indentation.
If a new type of string prefix is made to auto-dedent, maybe the substitutions should match the local indentation.
Some related stackoverflow posts:

https://stackoverflow.com/questions/36739667/python-templates-for-generating-python-code-with-proper-multiline-indentation

https://stackoverflow.com/a/57189263/2976410

I.e. ideally we would have:
```python
def make_g_code():
  nl='\n'
  return d"""\
    def g():
      {nl.join(something(i) for i in range(n))}
      return something_else
    """
```
This still has issues. Newline needs to be put into a variable, for instance. In the case of using this template for languages, great many use braces for delimiting blocks and those need to be escaped inside f-strings.

An implementation that works with spaces only (does not suit my case where mixed indentation is possible) is here:

http://code.activestate.com/recipes/578835-string-templates-with-adaptive-indenting/

Please let me know if this is the wrong place to comment on this issue.
History
Date User Action Args
2020-04-03 10:54:09Miguel Amaralsetrecipients: + Miguel Amaral, rhettinger, gregory.p.smith, steven.daprano, methane, serhiy.storchaka, josh.r, mbussonn, pablogsal, remi.lapeyre, Marco Sulla
2020-04-03 10:54:09Miguel Amaralsetmessageid: <1585911249.79.0.778684644323.issue36906@roundup.psfhosted.org>
2020-04-03 10:54:09Miguel Amarallinkissue36906 messages
2020-04-03 10:54:09Miguel Amaralcreate