aws / aws/sagemaker-core

Sagemaker core is unimportable in warnings as error mode due to `SyntaxError: invalid escape sequence: '\|'`

Open
#244 2 comments 5 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
24
Forks
25
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**
A clear and concise description of what the bug is.

Sagemaker core cannot be imported when running python in warnings as error mode. This comes up a lot in test suites when running pytest in warnings as error mode.

I believe most of this is codegen, so likely will need a fix to the generator to remove invalid escape sequences. Potentially a CI check could be added down the road to ensure the files are importable. There shouldn't be warnings on import either.

**To reproduce**
A clear, step-by-step set of instructions to reproduce the bug.
The provided code need to be **complete** and **runnable**, if additional data is needed, please include them in the issue.

```bash
# In case the venv creation matters
python -m pip install uv
uv venv venv
. venv/Scripts/active

python --version
Python 3.13.1

python ./src/sagemaker_core/main/shapes.py
C:\sagemaker-core\src\sagemaker_core\main\shapes.py:5799: SyntaxWarning: invalid escape sequence '\|'
"""
C:\sagemaker-core\src\sagemaker_core\main\shapes.py:6604: SyntaxWarning: invalid escape sequence '\*'
"""
C:\sagemaker-core\src\sagemaker_core\main\shapes.py:8812: SyntaxWarning: invalid escape sequence '\*'
"""
C:\sagemaker-core\venv\Lib\site-packages\pydantic\_internal\_fields.py:192: UserWarning: Field name "json" in "MonitoringDatasetFormat" shadows an attribute in parent "Base"
warnings.warn(

python -W error ./src/sagemaker_core/main/shapes.py
File "C:\sagemaker-core\src\sagemaker_core\main\shapes.py", line 5799
"""
^^^
SyntaxError: invalid escape sequence '\|'

```

There's multiple files with this issue. I'm not sure how these are passing tests.

```bash
git grep -e '\\|'
src/sagemaker_core/main/resources.py: task: The machine learning task your model package accomplishes. Common machine learning tasks include object detection and image classification. The following tasks are supported by Inference Recommender: "IMAGE_CLASSIFICATION" \| "OBJECT_DETECTION" \| "TEXT_GENERATION" \|"IMAGE_SEGMENTATION" \| "FILL_MASK" \| "CLASSIFICATION" \| "REGRESSION" \| "OTHER". Specify "OTHER" if none of the tasks listed fit your use case.
src/sagemaker_core/main/shapes.py: domain: The machine learning domain of the model and its components. Valid Values: COMPUTER_VISION \| NATURAL_LANGUAGE_PROCESSING \| MACHINE_LEARNING
src/sagemaker_core/main/shapes.py: task: The machine learning task that the model accomplishes. Valid Values: IMAGE_CLASSIFICATION \| OBJECT_DETECTION \| TEXT_GENERATION \| IMAGE_SEGMENTATION \| FILL_MASK \| CLASSIFICATION \| REGRESSION \| OTHER
src/sagemaker_core/main/shapes.py: framework: The machine learning framework of the container image. Valid Values: TENSORFLOW \| PYTORCH \| XGBOOST \| SAGEMAKER-SCIKIT-LEARN
src/sagemaker_core/main/shapes.py: nearest_model_name: The name of a pre-trained machine learning model benchmarked by Amazon SageMaker Inference Recommender that matches your model. Valid Values: efficientnetb7 \| unet \| xgboost \| faster-rcnn-resnet101 \| nasnetlarge \| vgg16 \| inception-v3 \| mask-rcnn \| sagemaker-scikit-learn \| densenet201-gluon \| resnet18v2-gluon \| xception \| densenet201 \| yolov4 \| resnet152 \| bert-base-cased \| xceptionV1-keras \| resnet50 \| retinanet

```

**Expected behavior**
A clear and concise description of what you expected to happen.
No errors nor warnings on import.

**Screenshots or logs**
If applicable, add screenshots or logs to help explain your problem.

**Bug information**
A description of your system. Please provide:
- **SageMaker Core version**: main
- **Python version**: 3.13, 3.12, 3.11
- **Is the issue with autogen code or with generate code ?**: yes

**Additional context**
Add any other context about the problem here.

Contributor guide

Open the contributing guide

Research direction

Start by running `python -W error ./src/sagemaker_core/main/shapes.py` and reviewing the invalid escape sequences reported in `src/sagemaker_core/main/shapes.py` and `src/sagemaker_core/main/resources.py`. Trace the code-generation path mentioned in the issue and verify that generated modules import without warnings or errors under Python 3.11–3.13 with warnings treated as errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.