Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecation warning due to invalid escape sequences #16

Open
tirkarthi opened this issue Jul 20, 2020 · 2 comments
Open

Deprecation warning due to invalid escape sequences #16

tirkarthi opened this issue Jul 20, 2020 · 2 comments

Comments

@tirkarthi
Copy link

Deprecation warnings are raised due to invalid escape sequences. This can be fixed by using raw strings or escaping the literals. pyupgrade also helps in automatic conversion : https://github.com/asottile/pyupgrade/

find . -iname '*.py' | grep -Ev 'vendor|example|doc|sphinx' | xargs -P4 -I{} python3.8 -Wall -m py_compile {}
./telegraf/utils.py:9: DeprecationWarning: invalid escape sequence \)
  """
./telegraf/utils.py:19: DeprecationWarning: invalid escape sequence \,
  key = key.replace(",", "\,")
./telegraf/utils.py:20: DeprecationWarning: invalid escape sequence \ 
  key = key.replace(" ", "\ ")
./telegraf/utils.py:21: DeprecationWarning: invalid escape sequence \=
  key = key.replace("=", "\=")
./telegraf/tests.py:14: DeprecationWarning: invalid escape sequence \,
  self.assertEquals(format_string('foo,bar'), 'foo\,bar')
./telegraf/tests.py:15: DeprecationWarning: invalid escape sequence \ 
  self.assertEquals(format_string('foo bar'), 'foo\ bar')
./telegraf/tests.py:16: DeprecationWarning: invalid escape sequence \ 
  self.assertEquals(format_string('foo ,bar'), 'foo\ \,bar')
./telegraf/tests.py:17: DeprecationWarning: invalid escape sequence \ 
  self.assertEquals(format_string('foo ,bar,baz=foobar'), 'foo\ \,bar\,baz\=foobar')
./telegraf/tests.py:59: DeprecationWarning: invalid escape sequence \ 
  """white\ space,tag\ with\,\ comma=hello\,\ world value\,\ comma="foo\""""
@ianjohnsonspacex
Copy link

This is due to this line right here:https://github.com/paksu/pytelegraf/blob/master/telegraf/utils.py#L40

value = value.replace('"', '\"') does not escape as the author intended. '"' == '\"' is True, the backslash is not interpreted as a literal. To fix, replace that line with value = value.replace('"', '\\"')

@matejsp
Copy link

matejsp commented Oct 3, 2023

We are no longer getting an warning but syntax error:

  File "/opt/virtualenvs/py311/lib64/python3.11/site-packages/telegraf/__init__.py", line 4, in <module>
    from .client import TelegrafClient, HttpClient
  File "/opt/virtualenvs/py311/lib64/python3.11/site-packages/telegraf/client.py", line 2, in <module>
    from telegraf.protocol import Line
  File "/opt/virtualenvs/py311/lib64/python3.11/site-packages/telegraf/protocol.py", line 1, in <module>
    from telegraf.utils import format_string, format_value
  File "/opt/virtualenvs/py311/lib64/python3.11/site-packages/telegraf/utils.py", line 9
    """
    ^^^
SyntaxError: invalid escape sequence '\)'
Exit code: 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants