pydub icon indicating copy to clipboard operation
pydub copied to clipboard

"SyntaxWarning: invalid escape sequence \("

Open hellishvictor opened this issue 1 year ago • 9 comments

Hi, on Python v3.12 it shows the error:

SyntaxWarning: invalid escape sequence '( SyntaxWarning: invalid escape sequence ')

On v3.12 changed the meaning of the regular expressions, and in places where was used \. now is only .. So "utils.py" must be corrected from line 299:

    for token in extra_info[stream['index']]:
        m = re.match('([su]([0-9]{1,2})p?) (([0-9]{1,2}) bit)$', token)
        m2 = re.match('([su]([0-9]{1,2})p?)( (default))?$', token)
        if m:
            set_property(stream, 'sample_fmt', m.group(1))
            set_property(stream, 'bits_per_sample', int(m.group(2)))
            set_property(stream, 'bits_per_raw_sample', int(m.group(3)))
        elif m2:
            set_property(stream, 'sample_fmt', m2.group(1))
            set_property(stream, 'bits_per_sample', int(m2.group(2)))
            set_property(stream, 'bits_per_raw_sample', int(m2.group(2)))
        elif re.match('(flt)p?( (default))?$', token):
            set_property(stream, 'sample_fmt', token)
            set_property(stream, 'bits_per_sample', 32)
            set_property(stream, 'bits_per_raw_sample', 32)
        elif re.match('(dbl)p?( (default))?$', token):
            set_property(stream, 'sample_fmt', token)
            set_property(stream, 'bits_per_sample', 64)
            set_property(stream, 'bits_per_raw_sample', 64)
    return info

Cheers.

hellishvictor avatar Jul 14 '24 03:07 hellishvictor

Still an issue as of Feb 2025.

utils.py:300: SyntaxWarning: invalid escape sequence '\('
  m = re.match('([su]([0-9]{1,2})p?) \(([0-9]{1,2}) bit\)$', token)

utils.py:301: SyntaxWarning: invalid escape sequence '\('
  m2 = re.match('([su]([0-9]{1,2})p?)( \(default\))?$', token)

utils.py:310: SyntaxWarning: invalid escape sequence '\('
  elif re.match('(flt)p?( \(default\))?$', token):

utils.py:314: SyntaxWarning: invalid escape sequence '\('
  elif re.match('(dbl)p?( \(default\))?$', token):

indexing/loaders.py:25: SyntaxWarning: invalid escape sequence '\d'
  match = re.match("doclens.(\d+).json", filename)

EnjoyBacon7 avatar Feb 24 '25 15:02 EnjoyBacon7

Yep. Me too:

2025-03-17 19:03:46 /usr/local/lib/python3.12/site-packages/pydub/utils.py:300: SyntaxWarning: invalid escape sequence '\('
2025-03-17 19:03:46   m = re.match('([su]([0-9]{1,2})p?) \(([0-9]{1,2}) bit\)$', token)
2025-03-17 19:03:46 /usr/local/lib/python3.12/site-packages/pydub/utils.py:301: SyntaxWarning: invalid escape sequence '\('
2025-03-17 19:03:46   m2 = re.match('([su]([0-9]{1,2})p?)( \(default\))?$', token)
2025-03-17 19:03:46 /usr/local/lib/python3.12/site-packages/pydub/utils.py:310: SyntaxWarning: invalid escape sequence '\('
2025-03-17 19:03:46   elif re.match('(flt)p?( \(default\))?$', token):
2025-03-17 19:03:46 /usr/local/lib/python3.12/site-packages/pydub/utils.py:314: SyntaxWarning: invalid escape sequence '\('
2025-03-17 19:03:46   elif re.match('(dbl)p?( \(default\))?$', token):
2025-03-17 19:03:47 {"app.name": "brief", "app.version": "1.1.0", "app.logger": "stdout", "time": "2025-03-17 12:03:47,375", "level": "INFO", "log_id": 1, "message": "Starting app...", "filename": "main.py", "lineno": 55}

G2048 avatar Mar 17 '25 12:03 G2048

Same here

davletovalmir avatar Mar 31 '25 17:03 davletovalmir

Me too.

thomas-villani avatar Apr 11 '25 03:04 thomas-villani

Please fix this 🙏

markbackman avatar Aug 02 '25 12:08 markbackman

Facing the same issue on Python 3.13

emZubair avatar Aug 18 '25 12:08 emZubair

Still in august :-)

surak avatar Aug 20 '25 14:08 surak

jup, still an issue

lennardkorte avatar Sep 03 '25 19:09 lennardkorte

Fixed it using pozalabs-pydub==0.37.0

pydub package not maintained anymore

lennardkorte avatar Sep 03 '25 20:09 lennardkorte