DeprecationWarning: invalid escape sequence
pabs3 opened this issue · 4 comments
pabs3 commented
When running the tests I get a few DeprecationWarning
messages:
oci/base_client.py:43: DeprecationWarning: invalid escape sequence \(
DICT_VALUE_TYPE_REGEX = re.compile('dict\(str, (.+?)\)$') # noqa: W605
oci/base_client.py:44: DeprecationWarning: invalid escape sequence \[
LIST_ITEM_TYPE_REGEX = re.compile('list\[(.+?)\]$') # noqa: W605
base_client.py:825: DeprecationWarning: invalid escape sequence \[
sub_kls = re.match('list\[(.*)\]', cls).group(1) # noqa: W605
oci/base_client.py:830: DeprecationWarning: invalid escape sequence \(
sub_kls = re.match('dict\(([^,]*), (.*)\)', cls).group(2) # noqa: W605
Since these are regexes the right thing to do use to use raw strings like this:
DICT_VALUE_TYPE_REGEX = re.compile(r'dict\(str, (.+?)\)$') # noqa: W605
waruwaruwaru commented
Hi @pabs3, what python version and what command did you run to test the oci-python-sdk? I tried to reproduce it on my end but I was not able to see the warning.
pabs3 commented
This is with Python 3.10.1-5 from Debian 12 (bookworm).
I discovered it when packaging oci-python-sdk and oci-cli for Debian
on behalf of my employer, who only use software in Debian packages.
I believe this is a new warning in Python 3.10 and later.
The command being run was this:
python3.10 -m pytest tests
The warnings should show up whenever importing oci.base_client though.
The solution is very simple, just turn all strings that contain
a regex into raw strings by prefixing them with an r character:
Convert this:
DICT_VALUE_TYPE_REGEX = re.compile('dict\(str, (.+?)\)$')
To this:
DICT_VALUE_TYPE_REGEX = re.compile(r'dict\(str, (.+?)\)$')
…--
bye,
pabs
https://bonedaddy.net/pabs3/
waruwaruwaru commented
Thank you, I will look more into this issue.
waruwaruwaru commented
@pabs3, the latest SDK should now have this issue fixed. Please feel free to re-open the issue if another problem comes up. Thank you for contributing to OCI Python SDK.