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

IDLE doesn't highlight f-strings properly #73257

Closed
KenzieTogami mannequin opened this issue Dec 26, 2016 · 11 comments
Closed

IDLE doesn't highlight f-strings properly #73257

KenzieTogami mannequin opened this issue Dec 26, 2016 · 11 comments
Assignees
Labels
3.7 (EOL) end of life topic-IDLE type-bug An unexpected behavior, bug, or error

Comments

@KenzieTogami
Copy link
Mannequin

KenzieTogami mannequin commented Dec 26, 2016

BPO 29071
Nosy @terryjreedy, @serhiy-storchaka, @ammaraskar
Files
  • python_idle_3.6_bug.png: Screenshot of f- and r- strings in IDLE
  • idle-f-string-highlight.diff
  • 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 = 'https://github.com/terryjreedy'
    closed_at = <Date 2016-12-27.05:20:10.842>
    created_at = <Date 2016-12-26.01:16:18.012>
    labels = ['expert-IDLE', 'type-bug', '3.7']
    title = "IDLE doesn't highlight f-strings properly"
    updated_at = <Date 2017-04-07.18:30:17.639>
    user = 'https://bugs.python.org/KenzieTogami'

    bugs.python.org fields:

    activity = <Date 2017-04-07.18:30:17.639>
    actor = 'terry.reedy'
    assignee = 'terry.reedy'
    closed = True
    closed_date = <Date 2016-12-27.05:20:10.842>
    closer = 'terry.reedy'
    components = ['IDLE']
    creation = <Date 2016-12-26.01:16:18.012>
    creator = 'Kenzie Togami'
    dependencies = []
    files = ['46037', '46048']
    hgrepos = []
    issue_num = 29071
    keywords = ['patch']
    message_count = 11.0
    messages = ['284010', '284051', '284062', '284064', '284065', '284420', '284439', '284440', '284472', '284479', '291284']
    nosy_count = 5.0
    nosy_names = ['terry.reedy', 'python-dev', 'serhiy.storchaka', 'ammar2', 'Kenzie Togami']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue29071'
    versions = ['Python 3.6', 'Python 3.7']

    @KenzieTogami
    Copy link
    Mannequin Author

    KenzieTogami mannequin commented Dec 26, 2016

    IDLE doesn't highlight f-strings like r-strings or u-strings. See the attached screenshot.

    @KenzieTogami KenzieTogami mannequin added topic-IDLE type-bug An unexpected behavior, bug, or error labels Dec 26, 2016
    @terryjreedy terryjreedy added the 3.7 (EOL) end of life label Dec 26, 2016
    @ammaraskar
    Copy link
    Member

    I've attached a patch that colorizes f-strings.

    The issue is marked as "test needed" which the dev guide says "... reporter should post a script or instructions to let a triager or developer reproduce the issue."

    Steps to re-create are to open an IDLE window and type in the code

    f"123"
    F"123"
    u"123"
    

    and notice the colorization difference.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Dec 27, 2016

    New changeset a48cc85e5706 by Terry Jan Reedy in branch '3.6':
    Issue bpo-29071: IDLE now colors f-string prefixes (but not invalid ur prefixes).
    https://hg.python.org/cpython/rev/a48cc85e5706

    @terryjreedy
    Copy link
    Member

    There are 10 possible f-string prefixes, including combinations with r/R. See
    https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals

    While adding these, I noticed that IDLE was coloring now invalid ur prefixes and deleted those.

    I decided to test by modifying the existing human visual htest.

    Ammar: thank you for submitting a patch. It happens that I wrote my patch before I saw your submission. If I had seen yours first, I might have given you a chance to finish it. Feel free to try another IDLE issue.

    @ammaraskar
    Copy link
    Member

    Not a problem, thank you for the encouragement.

    @serhiy-storchaka
    Copy link
    Member

    The regular expression can be simplified using local flags:

    • stringprefix = (r"(\br|R|u|U|f|F|fr|Fr|fR|FR|rf|rF|Rf|RF"
    •                "|b|B|br|Br|bR|BR|rb|rB|Rb|RB)?")
      

    + stringprefix = r"(?i:\br|u|f|fr|rf|b|br|rb)?"

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jan 2, 2017

    New changeset 62d3c0336df6 by Terry Jan Reedy in branch '3.6':
    Issue bpo-29071: Use local flags for IDLE colorizer string prefix matcher.
    https://hg.python.org/cpython/rev/62d3c0336df6

    @terryjreedy
    Copy link
    Member

    Thank you for the new feature (I presume) and its application. I disliked both writing and reading all the near duplication. I am posting this to python-list as an example of what the new feature is good for.

    @serhiy-storchaka
    Copy link
    Member

    Thank you for advertising the new feature. Would you like to improve the
    documentation? It always was the hardest part to me.

    @terryjreedy
    Copy link
    Member

    The doc appears to be carefully accurate, but the second sentence especially is a bit awkward. I will open a new issue.

    @terryjreedy
    Copy link
    Member

    bpo-29287 is about syntax highlighting the code within f-strings as code rather than as part of the string.

    @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.7 (EOL) end of life topic-IDLE type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants