Skip to content

Raise TypeError when Surface masks is provided without depth #3996

Description

@coderabbitai

Summary

pygame.Surface.__init__ currently ignores the masks argument when the caller does not provide depth. This can silently accept invalid values, including None and sequences with an invalid number of mask values.

Required change

Update Surface.__init__ argument validation so it raises TypeError when a caller provides masks without also providing depth.

Rationale

The masks argument is meaningful only with an explicit pixel depth. Silently ignoring it hides caller errors and makes the runtime behavior disagree with the intended API contract.

Affected area

  • Surface constructor implementation and its argument parsing
  • Tests for pygame.Surface(...) argument validation

Acceptance criteria

  • pygame.Surface(size, masks=value) raises TypeError when depth is omitted.
  • pygame.Surface(size, depth=depth, masks=None) raises TypeError.
  • Valid calls that provide both depth and four integer masks continue to work.
  • Tests cover the invalid and valid call forms.

References

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Surfacepygame.Surface

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions