Python 3.12+ SyntaxWarnings due to invalid escape sequences and return in finally block
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 68/100
Research direction
Inspect the cited expressions in tos/utils.py:1155 and tos/clientv2.py:874,878. Reproduce the import under Python 3.12+ and review the surrounding try/finally flow before making the warning-related changes. Done means the import no longer emits these SyntaxWarnings and the client behavior remains covered by the existing project checks.
Written by the indexing model from the issue text.
Description
Description
When using tos with Python 3.12+, multiple SyntaxWarnings are emitted on import, which can be noisy in production logs.
Warnings
1. Invalid escape sequence \d in tos/utils.py:1155
p = re.compile('^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$')
Fix: Use a raw string literal:
p = re.compile(r'^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$')
2. return in finally block in tos/clientv2.py:874,878
finally:
if len(args) <= 0 or not isinstance(args[0], TosClientV2):
return # line 874
threshold = args[0].high_latency_log_threshold
if threshold <= 0:
return # line 878
Having return inside a finally block overrides any exception being raised in the try or except blocks, which is likely not the intended behavior. Consider restructuring these as unconditional cleanup or moving the logic outside the finally.
Example output
.../tos/utils.py:1155: SyntaxWarning: "\d" is an invalid escape sequence. ... Did you mean "\\d"?
p = re.compile(...)
.../tos/clientv2.py:874: SyntaxWarning: 'return' in a 'finally' block
return
.../tos/clientv2.py:878: SyntaxWarning: 'return' in a 'finally' block
return
Environment
tosversion: 2.9.2- Python: 3.12+
- OS: macOS
These warnings are visible by default since Python 3.12, where DeprecationWarning for invalid escape sequences was upgraded to SyntaxWarning.
- Dominant language
- Python
- Stars
- 21
- Forks
- 11
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from volcengine/ve-tos-python-sdk
-
publish a wheel Open
Difficulty 3/5 1-2 days Newbie friendliness 65/100
-
Difficulty 3/5 1-2 days Newbie friendliness 42/100
volcengine/ve-tos-python-sdk#37 · 1 comment ·
-
Difficulty 1/5 Under an hour Newbie friendliness 35/100
volcengine/ve-tos-python-sdk#25 · 1 comment ·
All issues in volcengine/ve-tos-python-sdk
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100