API client generator template uses deprecated syntax for regular expressions
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 52/100
Research direction
Start in generator/cybersource-python-template/api_client.mustache at the referenced lines 424 and 429, then search the template for other regular expressions using non-raw strings. Regenerate the client if the project workflow permits it and run pytest under Python 3.12 or 3.13; done means the generated client no longer emits these SyntaxWarnings or related failures.
Written by the indexing model from the issue text.
Description
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: https://github.com/python/cpython/issues/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: https://github.com/CyberSource/cybersource-rest-client-python/blob/9d057e3bf85f9c8085394ec319bb2c74e843ffc7/generator/cybersource-python-template/api_client.mustache#L424
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.
- Dominant language
- Python
- Stars
- 24
- Forks
- 42
- Avg merge
- 29m
- Merged PRs (30d)
- 1
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from CyberSource/cybersource-rest-client-python
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
CyberSource/cybersource-rest-client-python#177 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
CyberSource/cybersource-rest-client-python#168 · 2 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
CyberSource/cybersource-rest-client-python#156 · 1 comment ·
All issues in CyberSource/cybersource-rest-client-python
Similar issues
-
upstream update
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
conan-io/conan-center-index#31098 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
john-kurkowski/tldextract#382 ·
-
comp/tools duplicate P2 sweeper:risk-compatibility tool/mcp type/bug
Difficulty 1/5 Under an hour Newbie friendliness 88/100
NousResearch/hermes-agent#132042 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
deepset-ai/haystack#13092 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 1-3 hours Newbie friendliness 85/100
feder-cr/invisible_playwright_mcp#1408 ·
Maintainers usually reply within 1 day