Fix Python 3.10 – 3.12+ Compatibility (Hashing and Syntax)#235
Open
bharathananth wants to merge 2 commits intostephenslab:masterfrom
Open
Fix Python 3.10 – 3.12+ Compatibility (Hashing and Syntax)#235bharathananth wants to merge 2 commits intostephenslab:masterfrom
bharathananth wants to merge 2 commits intostephenslab:masterfrom
Conversation
4d2c30e to
986f139
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR addresses several breaking changes and syntax warnings introduced in recent Python versions (3.10, 3.11, and 3.12). These changes ensure that dsc remains functional as older Python versions approach their End-of-Life (EOL).
Key Changes
Hashing Compatibility (Python 3.10+):
String Encoding: Updated all calls to xxh() and hashlib to encode Unicode strings to utf-8 bytes before hashing. This resolves TypeError: Strings must be encoded before hashing.
F-string Syntax: Fixed nested quote errors in dsc_parser.py that caused SyntaxError when using xxh inside list comprehensions.
Regex Refactoring (Python 3.12+):
Raw Strings: Converted strings containing escape sequences (e.g., [, (, {) to raw strings (r'...'). This resolves SyntaxWarning: invalid escape sequence, which is slated to become a hard SyntaxError in future Python releases.
Verification Results
I have verified these changes using the following steps:
[x] Vignette Testing: Successfully ran the official dsc vignettes (including one_sample_location (R scripts) and one_sample_location_python) to completion.
[x] Cache Integrity: Confirmed that the SoS caching mechanism correctly identifies and retrieves task results, proving that the updated hashing logic is consistent.
[x] Multi-Version Test: Verified the fix on Python 3.10, 3.11, and 3.12 environments.
Note on Dependencies
While this PR cleans up all SyntaxWarnings within the dsc source code itself, users may still see warnings originating from the PTable dependency (e.g., SyntaxWarning: "is" with a literal). These are upstream issues in PTable and do not affect the core logic of dsc. I recommend a future update to the dependency pins to a more modern version of prettytable to resolve those remaining notices.