GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test added in gh-104067 has an fstring with an invalid escape sequence · Issue #105784 · python/cpython

test added in gh-104067 has an fstring with an invalid escape sequence #105784

New issue
Copy link
New issue
Copy link
Closed
Closed
test added in gh-104067 has an fstring with an invalid escape sequence#105784
Copy link
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@mattip
mattip
opened on Jun 14, 2023
Issue body actions

Bug report

In response to #104049, a fix and a new test were added in #104067 and related PRs. The test in test_httpserver.py uses an fstring with an escape sequence, but does not use r:

f'listing for {self.base_url}/\?x=123'

I think the code (in two places) should be include an r: fr'listing for ...

On PyPy this is causing the test___all__.py test to fail, since it emits a warning when compiling the *.py to *.pyc. I am not sure why CPython is not seeing a similar problem. Perhaps compileall is run first? Or the warning filter captures the compilation as well as the import?

Your environment

  • CPython versions tested on: PyPy3.9 HEAD using stdlib 3.9.17
  • Operating system and architecture: any

Activity

  1. mattip
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Jun 14, 2023
  2. terryjreedy commented on Jun 14, 2023

    @terryjreedy
    terryjreedy
    on Jun 14, 2023
    Member
    More actions

    @mattip CPython does not issue this warning SyntaxWarning: invalid escape sequence '\?' until 3.12, though only for normal strings. What warning is PyPy3.9 emitting? (Note: try to minimize reproducing examples, as I did below ;-)

    @pablogsal In 3.12 and 3.13, f-strings are not warning about invalid escapes that get warnings in real strings. This seems like a bug.

    >>> f'\?'
    '\\?'
    >>> len(f'\?')
    2
    >>> '\?'
    <stdin>:1: SyntaxWarning: invalid escape sequence '\?'
    '\\?'
    
    
  3. mattip commented on Jun 14, 2023

    @mattip
    mattip
    on Jun 14, 2023
    ContributorAuthor
    More actions

    On python3.9.17 from Ubuntu, I get this

    $ python3.9 -Walways -c "abc = 'abc'; print(f'listing for {abc}/\?x=123')"
    <string>:1: DeprecationWarning: invalid escape sequence \?
    listing for abc/\?x=123
    
  4. mattip commented on Jun 14, 2023

    @mattip
    mattip
    on Jun 14, 2023
    ContributorAuthor
    More actions

    Adding an r makes it run without a warning

    $ python3.9 -Walways -c "abc = 'abc'; print(fr'listing for {abc}/\?x=123')"
    listing for abc/\?x=123
    
  5. terryjreedy commented on Jun 14, 2023

    @terryjreedy
    terryjreedy
    on Jun 14, 2023
    Member
    More actions

    Security patch #104067 was backported to 3.7, which is why it affects PyPy3.9.

    @ethanfurman @JelleZijlstra Do the tests added in #104067 require invalid escapes without an 'r' prefix? Or could the escape be changed or the 'r' added?

  6. pablogsal
    assigned
    lysnikolaou
    and unassigned
    lysnikolaou
    on Jun 14, 2023
  7. pablogsal commented on Jun 15, 2023

    @pablogsal
    pablogsal
    on Jun 15, 2023
    Member
    More actions

    @pablogsal In 3.12 and 3.13, f-strings are not warning about invalid escapes that get warnings in real strings. This seems like a bug.

    Fixed!

  8. mattip commented on Jun 15, 2023

    @mattip
    mattip
    on Jun 15, 2023
    ContributorAuthor
    More actions

    Thanks. I see that was backported to 3.12. I am curious why not backport it to all versions that contain the test added in #104067 (maybe excepting ones that will no longer be released)? People running the test without precompiling pyc files will see a DeprecationWarning, no?

    Edit: GAA, I didn't actually look at the fix: #105800 is not what I expected.

  9. mattip commented on Jun 15, 2023

    @mattip
    mattip
    on Jun 15, 2023
    ContributorAuthor
    More actions

    Try as I might, I cannot get CPython3.9 to emit a DeprecationWarning in the test_httpservers.py test. So I will add the r in the PyPy port of the stdlib tests. I am not sure why the test does not emit the warning on CPython3.9, since the f-string needs an r if run outside the test, but 🤷

    $ python3.9 -Walways -c "abc = 'abc'; print(f'listing for {abc}/\?x=123')"
    <string>:1: DeprecationWarning: invalid escape sequence \?
    listing for abc/\?x=123
    
  10. pablogsal commented on Jun 15, 2023

    @pablogsal
    pablogsal
    on Jun 15, 2023
    Member
    More actions

    Relevant: #105821

  11. lysnikolaou commented on Jun 20, 2023

    @lysnikolaou
    lysnikolaou
    on Jun 20, 2023
    Member
    More actions

    This can be closed. @mattip An r prefix has been added in #105822.

  12. lysnikolaou
    closed this as completedon Jun 20, 2023
  13. lazka commented on Jun 23, 2023

    @lazka
    lazka
    on Jun 23, 2023
    Contributor
    More actions

    Here it only warned/failed when bytecompile was needed, so if there wasn't a .pyc file already for test_httpservers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.