Skip to content

DeprecationWarning on Python 3.14: libusb_control_setup uses _pack_ without explicit _layout_ #111

@DedUndead

Description

@DedUndead

On Python 3.14, importing usb1 raises a DeprecationWarning that is treated as an error, preventing the module from loading.

Environment:

  • Python 3.14.3
  • python-libusb1 (latest from PyPI)
  • Ubuntu 24.04.3 LTS

Traceback

  usb1/__init__.py:61: in <module>
      from . import _libusb1 as libusb1
  usb1/_libusb1.py:1071: in <module>
      class libusb_control_setup(Structure):
  ctypes/_layout.py:81: in get_layout
      warnings._deprecated(
  E DeprecationWarning: Due to '_pack_', the 'libusb_control_setup' Structure will use memory layout
    compatible with MSVC (Windows). If this is intended, set _layout_ to 'ms'. The implicit default
    is deprecated and slated to become an error in Python 3.19.

Root cause:

Python 3.14 (changelog (https://docs.python.org/3.14/whatsnew/3.14.html)) deprecated the implicit behavior of _pack_ in ctypes.Structure without an explicit _layout_ attribute. The libusb_control_setup class in _libusb1.py uses _pack_ = 1 but does not declare _layout_.

Expected behavior

import usb1 should succeed without warnings on Python 3.14+.

Suggested fix:

Add _layout_ = "ms" to libusb_control_setup (if MSVC-compatible layout is intended), or replace _pack_ with the new layout mechanism. For example:

  class libusb_control_setup(Structure):
      _layout_ = "ms"
      _pack_ = 1
      _fields_ = [
          ...
      ]

Reproduction:

Import module running Python with warnings as errors (e.g. pytest default behavior):

python3.14 -W error::DeprecationWarning -c "import usb1"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions