Python 3.12+ SyntaxWarnings due to invalid escape sequences and return in finally block

Open Beginner friendly
#54 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
python
Domain
api

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

  • tos version: 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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from volcengine/ve-tos-python-sdk

All issues in volcengine/ve-tos-python-sdk

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.