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

BaseTools: Fix multiple 'invalid escape sequence' warnings in tests #6216

Merged
merged 2 commits into from
Sep 23, 2024

Conversation

mikebeaton
Copy link
Contributor

@mikebeaton mikebeaton commented Sep 18, 2024

Description

In Python 3.12 invalid escape sequences in strings moved from DeprecationWarning to SyntaxWarning (ref https://docs.python.org/3/whatsnew/changelog.html#python-3-12-0-final and search for gh-98401). In a future Python version this will become SyntaxError.

Multiple instances of these SyntaxWarnings are currently printed when running the BaseTools tests using Python 3.12 (though without actually failing the affected tests).

This commit updates all lines which were causing this type of warning.

Typical examples which needed fixing are:

  • "BaseTools\Source\Python" representing a path: "\S" and "\P" are invalid escape sequences, therefore left unchanged, therefore the test works (with a warning in Python 3.12). r"BaseTools\Source\Python" represents the same string, but with escapes turned off completely thus no warning.

  • Where '\t\s' is used as a regex pattern, then chr(9) + '\\s' is sent to the regex parser (with a warning in Python 3.12) since '\s' is not a valid Python escape sequence. This works correctly, though arguably for the wrong reasons. r'\t\s' sends the same as '\\t\\s', as originally intended and with no warning.

(Note that ' and " are not fundamentally different in Python.)

  • Breaking change?
  • Impacts security?
  • Includes tests?

How This Was Tested

Confirm all tests passing and no warnings printed after change, using either Python 3.11 or 3.12.

Integration Instructions

N/A

@mdkinney
Copy link
Member

Really glad to see addressing this before it breaks anything.

From looking at the changes, the specific impact is to convert strings to raw strings (r'') if the string contains a ''. Are there any other cases? Perhaps add that description to the commit message.

@mikebeaton
Copy link
Contributor Author

Updated with more explanation in commit message.

@mikebeaton mikebeaton force-pushed the basetools-syntax-warning branch 4 times, most recently from 119e4d0 to e1d5f90 Compare September 18, 2024 21:40
@lgao4
Copy link
Contributor

lgao4 commented Sep 20, 2024

I agree to merge this change.

@lgao4 lgao4 added the push Auto push patch series in PR if all checks pass label Sep 23, 2024
In Python 3.12 invalid escape sequences in strings moved from
DeprecationWarning to SyntaxWarning
(ref https://docs.python.org/3/whatsnew/changelog.html#python-3-12-0-final
and search for gh-98401). In a future Python version this will become
SyntaxError.

Multiple instances of these SyntaxWarnings are currently printed when
running the BaseTools tests using Python 3.12 (though without actually
failing the affected tests).

This commit updates all lines which were causing this type of warning.

Typical examples which needed fixing are:

- "BaseTools\Source\Python" representing a path: "\S" and "\P" are invalid
escape sequences, therefore left unchanged, therefore the test works
(with a warning in Python 3.12). r"BaseTools\Source\Python" represents
the same string, but with escapes turned off completely thus no warning.

- Where '\t\s' is used as a regex pattern, then chr(9) + '\\s' is sent
to the regex parser (with a warning in Python 3.12) since '\s' is not a
valid Python escape sequence. This works correctly, though arguably for
the wrong reasons. r'\t\s' sends the same as '\\t\\s', as originally
intended and with no warning.

(Note that ' and " are not fundamentally different in Python.)

Signed-off-by: Mike Beaton <mjsbeaton@gmail.com>
@mergify mergify bot merged commit 6820004 into tianocore:master Sep 23, 2024
126 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
push Auto push patch series in PR if all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants