Skip to content

Syntax warnings with Python 3.12 #67

@datalogics-kam

Description

@datalogics-kam

Describe the bug
Syntax warnings with Python 3.12.

To Reproduce
In a checkout:

python3.12 -m venv .venv
. .venv/bin/activate
python -m pip install -r requirements.txt
python -B -c 'import onepassword'

Output:

/Users/kam/src/1password-client/onepassword/utils.py:9: SyntaxWarning: invalid escape sequence '\@'
  master_password_regex = 'Enter the password for [a-zA-Z0-9._%+-]+\@[a-zA-Z0-9-]+\.[a-zA-z]{2,4} at ' \
/Users/kam/src/1password-client/onepassword/utils.py:10: SyntaxWarning: invalid escape sequence '\.'
  '[a-zA-Z0-9-.]+\.1password+\.[a-zA-z]{2,4}'
/Users/kam/src/1password-client/onepassword/utils.py:70: SyntaxWarning: invalid escape sequence '\('
  index = p.expect([pexpect.EOF, "\(401\) Unauthorized"])

Note that -B is required to not write bytecode, because once the code is parsed, the warnings don't come again.

Also, Ruff is useful for checking for this and other code gotchas.

❯ ruff check --select W605 --target-version py312
onepassword/utils.py:9:66: W605 [*] Invalid escape sequence: `\@`
onepassword/utils.py:9:81: W605 [*] Invalid escape sequence: `\.`
onepassword/utils.py:10:40: W605 [*] Invalid escape sequence: `\.`
onepassword/utils.py:10:52: W605 [*] Invalid escape sequence: `\.`
onepassword/utils.py:70:45: W605 [*] Invalid escape sequence: `\(`
onepassword/utils.py:70:50: W605 [*] Invalid escape sequence: `\)`
Found 6 errors.
[*] 6 fixable with the `--fix` option.

Expected behavior
No output.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: macOS

Additional context
See also:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions