Skip to content

fix: Python SyntaxWarning: invalid escape sequence warnings #459

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

benglewis
Copy link
Contributor

This package produces the following Python warnings:

python3.13/site-packages/label_studio_sdk/_extensions/label_studio_tools/core/label_config.py:137: SyntaxWarning: invalid escape sequence '\$'
  expression = "^\$[A-Za-z_]+$"
python3.13/site-packages/label_studio_sdk/files/client.py:122: SyntaxWarning: invalid escape sequence '\ '
  curl -H 'Authorization: Token abc123' \ -X POST 'https://localhost:8080/api/import/file-upload/245' -F ‘file=@path/to/my_file.csv’
python3.13/site-packages/label_studio_sdk/files/client.py:448: SyntaxWarning: invalid escape sequence '\ '
  curl -H 'Authorization: Token abc123' \ -X POST 'https://localhost:8080/api/import/file-upload/245' -F ‘file=@path/to/my_file.csv’
python3.13/site-packages/label_studio_sdk/projects/client.py:533: SyntaxWarning: invalid escape sequence '\.'
  #### 1\. **POST with data**
python3.13/site-packages/label_studio_sdk/projects/client.py:1248: SyntaxWarning: invalid escape sequence '\.'
  #### 1\. **POST with data**
python3.13/site-packages/label_studio_sdk/projects/exports/client.py:58: SyntaxWarning: invalid escape sequence '\&'
  curl -X GET https://localhost:8080/api/projects/{id}/export?ids[]=123\&ids]=345 -H 'Authorization: Token abc123' --output 'annotations.json'
python3.13/site-packages/label_studio_sdk/projects/exports/client.py:607: SyntaxWarning: invalid escape sequence '\&'
  curl -X GET https://localhost:8080/api/projects/{id}/export?ids[]=123\&ids]=345 -H 'Authorization: Token abc123' --output 'annotations.json'

The following PR fixes those Python warnings.
It was also raised in #453 and this fixes #453 too as a result

@benglewis benglewis changed the title Fix Python warnings fix: Python SyntaxWarning: invalid escape sequence warnings May 14, 2025
@makseq
Copy link
Member

makseq commented May 22, 2025

Hi, thank your for your PR!

This fix makes sense:
https://github.com/HumanSignal/label-studio-sdk/pull/459/files#diff-bf9b5c881f75a125c7d11f2878d4c5a4e7abfc8248d8548712c35364ce3e4129L137

But unfortunately others don't make, because all client.py files are autogenerated by fern:
https://github.com/HumanSignal/label-studio-client-generator

@benglewis
Copy link
Contributor Author

@makseq Got it. Should I revert the other changes then? Is there a way to fix this in the label-studio-client-generator?

@benglewis
Copy link
Contributor Author

@makseq @pakelley @farioas Any ideas how I can fix this in the Fern generated parts? I am not familiar enough with Fern to fully understand what is generated and how exactly. Is this a bug in Fern itself? If so, then can you help me to produce an appropriate GitHub Issue for Fern?

@benglewis
Copy link
Contributor Author

@makseq I'm following up this. You approved this PR already 2 weeks ago, and I still don't exactly understand the path towards fixing the warnings 🙏

@farioas
Copy link
Member

farioas commented Jun 11, 2025

@benglewis Some code is generated from the OpenAPI schema using the Fern library. You can identify these files by 1st line:
# This file was auto-generated by Fern from our API Definition.
We need to wait for them to fix the issue on their side before we can apply any changes.

But I don't see it's was ever claimed: https://github.com/search?q=repo%3Afern-api%2Ffern+%27%22%22%22%27+path%3A%2F%5Egenerators%5C%2Fpython%5C%2Fsrc%5C%2Ffern_python%5C%2F%2F&type=code

@farioas
Copy link
Member

farioas commented Jun 11, 2025

Please update your change to include only files that do not start with the line # This file was auto-generated by Fern from our API Definition.

@benglewis
Copy link
Contributor Author

benglewis commented Jun 16, 2025

I have reverted the Python files changes.
It looks like the first \ issue is actually from the docs in

curl -H 'Authorization: Token abc123' \ -X POST
and
#### 1\. **POST with data**
.
It looks like the second \& issue is actually from the docs in
https://localhost:8080/api/projects/{id}/export?ids[]=123\&ids[]=345 -H

I suggest that I change the docs instead and let the Fern part be updated automatically?
For the incorrect \ in the middle of a curl call line and the 1\., I think that it should be as simple as removing the symbol. In the \& case, I may need to wrap the section in quotation marks so that it still works, but that should be fine.

@benglewis
Copy link
Contributor Author

OK... so I just realized that this indeed actually look to be coming from https://github.com/HumanSignal/label-studio-client-generator - they may be bugs in Fern, I am not sure, but in the meantime, I have tried to implement workarounds in that repository and opened a Pull Request there too, in order to fix these issues

@benglewis
Copy link
Contributor Author

@farioas Let me know if you need any changes

@benglewis
Copy link
Contributor Author

@farioas I also believe that the Gitleaks GitHub Actions workflow is failing due to me not being a developer in the humansignal/label-studio-sdk repository. I don't know if I can work around that issue. Please also take a look at HumanSignal/label-studio-client-generator#79 and let me know if there are any changes that I should make there or if it can be merged too 🙏

@benglewis
Copy link
Contributor Author

@farioas @makseq Is there something that I can do to get these two PRs merged? 🙏 :)

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

Successfully merging this pull request may close these issues.

Missing the r prefix before a regex string in Python
3 participants