Skip to content

SyntaxWarning in Python 3.12  #2189

@fepegar

Description

@fepegar

Describe the bug

This is not really a bug, just a slightly annoying warning:

SyntaxWarning: invalid escape sequence '\s'

It happens because of this line

\sa itk::simple::DiscreteGaussianImageFilter for the object oriented interface

which was introduced four years ago in 3acb4c5.

I haven't seen that syntax in other Python files, but I have seen in some header files such as

* \sa itk::BSplineInterpolateImageFunction

so I'm guessing it was an accident.

Python 3.12 upgraded the DeprecationWarning to a SyntaxWarning and that's why we see it now by default.

To Reproduce

Python 3.11

uv venv --python 3.11 sitk311
source sitk311/bin/activate
uv pip install SimpleITK
python -Wd -c "import SimpleITK"  # note the flags to show deprecation warnings

Output:

<frozen importlib._bootstrap>:241: DeprecationWarning: builtin type SwigPyPacked has no __module__ attribute
<frozen importlib._bootstrap>:241: DeprecationWarning: builtin type SwigPyObject has no __module__ attribute
<frozen importlib._bootstrap>:241: DeprecationWarning: builtin type swigvarlink has no __module__ attribute
/private/tmp/sitk311/lib/python3.11/site-packages/SimpleITK/extra.py:466: DeprecationWarning: invalid escape sequence '\s'
  """Blurs an image by separable convolution with discrete

Python 3.12

uv venv --python 3.12 sitk312
source sitk312/bin/activate
uv pip install SimpleITK
python -c "import SimpleITK"

Output:

/private/tmp/sitk312/lib/python3.12/site-packages/SimpleITK/extra.py:466: SyntaxWarning: invalid escape sequence '\s'
  """Blurs an image by separable convolution with discrete

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions