Skip to content

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

@jmahlik

Description

@jmahlik

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.

# 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.

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions