Miguel Amaral <amaral.migu...@gmail.com> added the comment:

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.

----------
nosy: +Miguel Amaral

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue36906>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to