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

Update validation.py to avoid SyntaxError #1664

Merged

Conversation

emilyanndavis
Copy link
Member

@emilyanndavis emilyanndavis commented Oct 24, 2024

Description

Fixes #1663 with Python raw string notation, as recommended by the Python re module docs:

Also, please note that any invalid escape sequences in Python’s usage of the backslash in string literals now generate a SyntaxWarning and in the future this will become a SyntaxError. This behaviour will happen even if it is a valid escape sequence for a regular expression.

The solution is to use Python’s raw string notation for regular expression patterns; backslashes are not handled in any special way in a string literal prefixed with 'r'.

I still don't know what triggered the switch to SyntaxError, since even the Python 3.13 docs still describe this as "future" behavior, but in any case the raw string notation appears to solve the problem.

Checklist

- [ ] Updated HISTORY.rst and link to any relevant issue (if these changes are user-facing)
- [ ] Updated the user's guide (if needed)
- [ ] Tested the Workbench UI (if relevant)

@emilyanndavis emilyanndavis marked this pull request as ready for review October 24, 2024 20:07
@phargogh phargogh self-requested a review October 24, 2024 20:28
Copy link
Member

@phargogh phargogh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into this @emilyanndavis !

Looking at the docs, it appears that in python 3.11, a DeprecationWarning was raised, and in python 3.12+ this warning was changed to SyntaxWarning. This change matters because at the bottom of pyproject.toml, we tell pytest to elevate all warnings to exceptions except for DeprecationWarning, FutureWarning, and one very specific RuntimeWarning related to an issue on M1 chips. So that's why this behavior changed suddenly.

@phargogh phargogh merged commit f7c5393 into natcap:main Oct 24, 2024
29 checks passed
@emilyanndavis
Copy link
Member Author

Ooh, mystery solved! 🕵🏻 Thanks, @phargogh!

@emilyanndavis emilyanndavis deleted the bugfix/1663-validation-py-syntax-error branch October 24, 2024 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Validate sample data" task—and model tests—fail on a SyntaxError in validation.py
2 participants