8000 SyntaxWarning: invalid escape sequence when using Python 3.12 · Issue #4823 · iovisor/bcc · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
SyntaxWarning: invalid escape sequence when using Python 3.12 #4823
Closed
@goodrone

Description

@goodrone

Python 3.12 improves handling of incorrect escape sequences, see https://docs.python.org/3/whatsnew/3.12.html#other-language-changes

This is a typical scenario in regular expressions. With Python 3.12, there are currently 5 places that use invalid escape sequences:

  1. examples/tracing/task_switch.py:9: SyntaxWarning: invalid escape sequence '\.'
      b.attach_kprobe(event_re="^finish_task_switch$|^finish_task_switch\.isra\.\d$",
    
  2. src/python/bcc/__init__.py:758: SyntaxWarning: invalid escape sequence '\.'
      elif re.match(b'^.*\.cold(\.\d+)?$', fn):
    
  3. tests/python/test_tools_smoke.py:67: SyntaxWarning: invalid escape sequence '\s'
      reg = re.compile("^%s\s" % mod)
    
  4. tests/python/test_trace2.py:34: SyntaxWarning: invalid escape sequence '\.'
      b.attach_kprobe(event_re=b"^finish_task_switch$|^finish_task_switch\.isra\.\d$",
    
  5. tools/exitsnoop.py:207: SyntaxWarning: invalid escape sequence '\.'
      if re.match('^3\.10\..*el7.*$', platform.release()): # Centos/Red Hat
    

In all places I think it will be enough to use Python raw strings, r'...'.

Here is the command I used to look up all of them:

for f in $(git ls-files | grep -E '\.py$'); do python3 -m py_compile $f; done

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

      0