Description
Using the REST Client library in a project with Python >= 3.12 results in chattery SyntaxWarning messages, and sometimes pytest failures.
Starting in Python 3.6, strings that contain invalid escape sequences raise a DeprecationWarning. This includes regular strings that are used for regex expressions, as regex uses backslashed characters to denote operators/classes/etc. and those don't match up with escape sequences. DeprecationWarning is usually silent, but in 3.12 this was changed so that these now emit a SyntaxWarning, which isn't silent.
Compounding the issue is that pytest treats these as a failure when using Python 3.13.
More Info
The change is noted in the What's New for 3.12 here: https://docs.python.org/3/whatsnew/3.12.html#other-language-changes
See also the discussion here: python/cpython#98401
I created a very simple test case that demonstrates the issue. It is available here: https://github.com/jkachel/cybersource-rest-error
The pytest error output is in a comment below to keep this issue from being too long.
Potential Fix
Regular expressions should use raw strings.
The main offenders seem to be here:
|
sub_kls = re.match('list\[(.*)\]', klass).group(1) |
and in line 429 in the same file. The fix should be as simple as adding r to the start of those regex strings. I don't have a workflow set up for regenerating this client, and there may be other instances where this should be fixed that I don't know about, so I haven't tried to fix it.
Workaround
Client code can use the warnings library to filter SyntaxWarning when importing the CyberSource API client. Ex:
import warnings
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=SyntaxWarning)
from CyberSource import ApiClient, OrdersApi
This resolves the issue in the short term but these should be fixed - as noted in the change, Python will (eventually) start emitting SyntaxError for these issues.
Description
Using the REST Client library in a project with Python >= 3.12 results in chattery
SyntaxWarningmessages, and sometimespytestfailures.Starting in Python 3.6, strings that contain invalid escape sequences raise a
DeprecationWarning. This includes regular strings that are used for regex expressions, as regex uses backslashed characters to denote operators/classes/etc. and those don't match up with escape sequences.DeprecationWarningis usually silent, but in 3.12 this was changed so that these now emit aSyntaxWarning, which isn't silent.Compounding the issue is that
pytesttreats these as a failure when using Python 3.13.More Info
The change is noted in the What's New for 3.12 here: https://docs.python.org/3/whatsnew/3.12.html#other-language-changes
See also the discussion here: python/cpython#98401
I created a very simple test case that demonstrates the issue. It is available here: https://github.com/jkachel/cybersource-rest-error
The pytest error output is in a comment below to keep this issue from being too long.
Potential Fix
Regular expressions should use raw strings.
The main offenders seem to be here:
cybersource-rest-client-python/generator/cybersource-python-template/api_client.mustache
Line 424 in 9d057e3
and in line 429 in the same file. The fix should be as simple as adding
rto the start of those regex strings. I don't have a workflow set up for regenerating this client, and there may be other instances where this should be fixed that I don't know about, so I haven't tried to fix it.Workaround
Client code can use the
warningslibrary to filterSyntaxWarningwhen importing the CyberSource API client. Ex:This resolves the issue in the short term but these should be fixed - as noted in the change, Python will (eventually) start emitting
SyntaxErrorfor these issues.