-
Notifications
You must be signed in to change notification settings - Fork 32
Fix python3.12 SyntaxWarning: invalid escape sequence #66
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
Conversation
6098c54 to
f9df142
Compare
shwetagkhatri
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rest of the changes are valid and correct.
| return deco | ||
|
|
||
| @staticVars(search_term=re.compile("gfx[0-9a-fA-F]+")) | ||
| @staticVars(search_term=re.compile(r"gfx[0-9a-fA-F]+")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no practical difference between using a raw string and a non-raw string, as there are no backslash escape characters involved here.
| term1 = re.compile("Cannot allocate memory") | ||
| term2 = re.compile("HSA_STATUS_ERROR_OUT_OF_RESOURCES") | ||
| term1 = re.compile(r"Cannot allocate memory") | ||
| term2 = re.compile(r"HSA_STATUS_ERROR_OUT_OF_RESOURCES") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no practical difference between using a raw string and a non-raw string, as there are no backslash escape characters involved here.
| prop_path = node_path + '/properties' | ||
| if os.path.isfile(prop_path) and os.access(prop_path, os.R_OK): | ||
| target_search_term = re.compile("gfx_target_version.+") | ||
| target_search_term = re.compile(r"gfx_target_version.+") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no practical difference between using a raw string and a non-raw string, as there are no backslash escape characters involved here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for reviewing. Yes, both normal string and raw string can be used here to achieve similar result.
What's your opinion? I think making all re.compile use raw strings prevents making mistakes in the future (if regular expressions is needed here). While reverting these 3 lines makes this commit minimal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. I agree that using raw string will prevent future mistakes incase escape characters are added here. Please go ahead with the commit.
|
Hi @littlewu2508, |
Use raw strings for regular expression. This is nearly same with ROCm#55 which is pulled internally earlier Reference: https://docs.python.org/dev/whatsnew/3.12.html#other-language-changes Signed-off-by: Selene <[email protected]>
f9df142 to
90c2051
Compare
I see. I have updated the commit message to mention that PR. You can close this PR once you've apply it properly (although I wonder why that PR is not merged to master publicly, so I don't have to fix this independently) |
Makes all re.compile function calls use raw string to prevent Syntax warning in future, if backslash escape characters are used in regular expressions https: //github.com//pull/66 Suggested-by: Author: Yiyang Wu <[email protected] Change-Id: I6c7aaf016c588bb2ae5a0f979da7d423a78d6ec3
Makes all re.compile function calls use raw string to prevent Syntax warning in future, if backslash escape characters are used in regular expressions https: //github.com/ROCm/rocminfo/pull/66 Suggested-by: Author: Yiyang Wu <[email protected] Change-Id: I6c7aaf016c588bb2ae5a0f979da7d423a78d6ec3 [ROCm/rocminfo commit: e171664]
Makes all re.compile function calls use raw string to prevent Syntax warning in future, if backslash escape characters are used in regular expressions https: //github.com//pull/66 Suggested-by: Author: Yiyang Wu <[email protected] Change-Id: I6c7aaf016c588bb2ae5a0f979da7d423a78d6ec3 [ROCm/rocminfo commit: e171664]
Running rocm_agent_enumerator in python 3.12 gives the following syntax warning:
The fix is to use raw strings for regular expression
Reference: https://docs.python.org/dev/whatsnew/3.12.html#other-language-changes