Skip to content

pygame.mixer.music isn't a real module #3397

Open
@aatle

Description

@aatle

Environment:
pygame-ce 2.5.4.dev1

Current behavior:
The music module currently exists only as an attribute of pygame.mixer, and so isn't a real module.
Certain import statements fail because of this.

Expected behavior:
pygame.mixer.music should exist in sys.modules so that imports work as expected.
Additionally, the stubs should reflect any fixes for this.

Test code

from pygame.mixer.music import queue
import pygame.mixer.music

Stack trace/error output/other error logs

$ python blank.py
pygame-ce 2.5.4.dev1 (SDL 2.32.2, Python 3.13.0)
Traceback (most recent call last):
  File "C:\Users\...\main.py", line 1, in <module>
    from pygame.mixer.music import queue
ModuleNotFoundError: No module named 'pygame.mixer.music'; 'pygame.mixer' is not a package

mypy:

Cannot find implementation or library stub for module named "pygame.mixer.music" mypy(import-not-found)

Comments
It's a relatively minor issue but I wanted to put this up for discussion.
I consider this a bug because it would be expected that pygame.mixer.music is a real module.
While pygame.mixer_music (the actual module) exists, it is undocumented. It is exposed as an exported module in the stubs though.
The fix would be to set sys.modules["pygame.mixer.music"] = mixer_music, but this doesn't work for stubs. pygame.mixer probably has to be turned into a package in the stubs for this to be fixed.
A possible change that has been discussed before is to alias pygame.music to pygame.mixer.music.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugNot working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions