Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: i-Strings #80809

Closed
AdityaShankar mannequin opened this issue Apr 14, 2019 · 3 comments
Closed

Enhancement: i-Strings #80809

AdityaShankar mannequin opened this issue Apr 14, 2019 · 3 comments
Labels
3.9 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@AdityaShankar
Copy link
Mannequin

AdityaShankar mannequin commented Apr 14, 2019

BPO 36628
Nosy @tirkarthi

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2019-04-14.14:10:05.248>
created_at = <Date 2019-04-14.13:58:27.055>
labels = ['interpreter-core', 'type-feature', '3.9']
title = 'Enhancement: i-Strings'
updated_at = <Date 2019-04-15.06:26:08.004>
user = 'https://bugs.python.org/AdityaShankar'

bugs.python.org fields:

activity = <Date 2019-04-15.06:26:08.004>
actor = 'Aditya Shankar'
assignee = 'none'
closed = True
closed_date = <Date 2019-04-14.14:10:05.248>
closer = 'SilentGhost'
components = ['Interpreter Core']
creation = <Date 2019-04-14.13:58:27.055>
creator = 'Aditya Shankar'
dependencies = []
files = []
hgrepos = []
issue_num = 36628
keywords = []
message_count = 3.0
messages = ['340208', '340210', '340213']
nosy_count = 3.0
nosy_names = ['SilentGhost', 'xtreak', 'Aditya Shankar']
pr_nums = []
priority = 'normal'
resolution = 'duplicate'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue36628'
versions = ['Python 3.9']

@AdityaShankar
Copy link
Mannequin Author

AdityaShankar mannequin commented Apr 14, 2019

Problem: multiline strings are a pain to represent (other than of-course in docstrings), representing a multiline string inside a function looks something like this -

def foo():
    # some code
    ...
    ...
    # some code
    text = """abc meta alpha chronos
dudes uptomes this text
is nonsense"""
    return somethingwith(text)

or

def foo():
    # some code
    ...
    ...
    # some code
    text = "\n".join(["abc meta alpha chronos",
                      "dudes uptomes this text",
                      "is nonsense"])
    return somethingwith(text)

an enhancement would be -

def foo():
    # some code
    ...
    ...
    # some code
    text = i"""
            abc meta alpha chronos
            dudes uptomes this text
            is nonsense
            """
    return somethingwith(text)
i.e. all initial spaces are not considered as a part of the string in each ine

for example while throwing an exception -
def foo(bad_param):
    ...
    try:
        some_function_on(bad_param)
    except someException:
        throw(fi"""
                you cant do that because, and I'm gonna explain
                this in a paragraph of text with this {variable}
                because it explains things more clearly, also
                here is the {bad_param}
                """)
    ...
which is far neater than -

def foo(bad_param):
    ...
    try:
        some_function_on(bad_param)
    except someException:
        throw(f"""you cant do that because, and I'm gonna explain
this in a paragraph of text with this {variable}
because it explains things more clearly, also
here is the {bad_param}""")
    ...

pros:
- represented code is closer to output text
- implementation should not be too hard

@AdityaShankar AdityaShankar mannequin added 3.9 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement labels Apr 14, 2019
@SilentGhost
Copy link
Mannequin

SilentGhost mannequin commented Apr 14, 2019

This type of enhancements should be in the first place discussed on python-ideas mailing list and a PEP would probably be needed at the second stage. Not that I think it's likely this suggestion has much chance.

What you're desiring can already be implemented using implicit string concatenation (with addition of some parentheses in some of your examples).

@SilentGhost SilentGhost mannequin closed this as completed Apr 14, 2019
@tirkarthi
Copy link
Member

Some discussions in the past and the common suggestion/idiom is to use textwrap.dedent. I agree with @SilentGhost that it should be first brought up in python-ideas and also addressing the concerns for similar proposal in the past if they are still valid.

Proposes d"" for indentation : https://mail.python.org/pipermail/python-ideas/2010-November/008589.html
https://mail.python.org/pipermail/python-dev/2005-July/054649.html

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.9 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant