Skip to content

DeprecationWarning: PY_SSIZE_T_CLEAN will be required for '#' formats #3750

@mgedmin

Description

@mgedmin

What did you do?

Ran my test suite on Python 3.8.0a3

What did you expect to happen?

The test to pass

What actually happened?

The tests did pass, but there were new deprecation warnings from Pillow:

.../.tox/py38/lib/python3.8/site-packages/PIL/Image.py:477: DeprecationWarning: PY_SSIZE_T_CLEAN will be required for '#' formats
    return encoder(mode, *args + extra)

These were introduced by https://bugs.python.org/issue36381 to warn about an upcoming Python C API change. The meaning of PY_SSIZE_T_CLEAN is described in https://python.readthedocs.io/en/stable/c-api/arg.html#strings-and-buffers.

What Pillow needs to do is:

  • find all invocations of PyArg_Parse and related functions that use # formats
    make sure the type of the length argument is a Py_ssize_t
  • #define PY_SSIZE_T_CLEAN above the #include <Python.h>.

PY_SSIZE_T_CLEAN was introduced in Python 2.5 so there shouldn't be any backwards-compatibility issues.

What are your OS, Python and Pillow versions?

  • OS: Ubuntu 18.10
  • Python: 3.8.0a3
  • Pillow: 5.4.1

Reproduction

#!/usr/bin/env python3.8
import warnings
warnings.simplefilter("once")
from PIL import Image
Image.new("RGB", (1, 1)).save("/tmp/pixel.png")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions