-
Notifications
You must be signed in to change notification settings - Fork 37
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
API client generator template uses deprecated syntax for regular expressions #143
Comments
Pytest output (note that this is actually when running 3.12):
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
Using the REST Client library in a project with Python >= 3.12 results in chattery
SyntaxWarning
messages, and sometimespytest
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 aSyntaxWarning
, 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:
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
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 filterSyntaxWarning
when 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
SyntaxError
for these issues.The text was updated successfully, but these errors were encountered: