Skip to content

refactor: consolidate media constraint classes via generic bases #175

Description

@Kamilbenkirane

The six media constraint classes in constraints.py (ImageConstraint, ImagesConstraint, VideoConstraint, VideosConstraint, AudioConstraint, AudiosConstraint) contain nearly identical validation logic (~186 lines), differing only in artifact type, MIME enum, and label string.

Proposal: Introduce two private base classes (_MediaConstraint, _MediaListConstraint) to centralize the shared validation. Each public class becomes a thin subclass with typed __call__ signatures preserved for get_constraint_input_type introspection compatibility.

  • Zero public API changes (same class names, constructors, error messages)
  • All existing tests pass unchanged
  • Net reduction of ~80 lines
  • Adding a new media type becomes 2 thin subclasses instead of 2 copy-paste blocks

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions