roboflow/supervision · error · ValueError

Only class instances are supported, not classes.

Error message

Only class instances are supported, not classes.

What it means

Raised by get_instance_variables() in supervision.utils.internal when the `instance` argument is a class object (e.g. Detections) rather than an instance (e.g. Detections(xyxy=...)). The helper inspects public attributes via inspect.getmembers, which behaves very differently on classes, so it explicitly rejects them to avoid misleading results.

Source

Thrown at src/supervision/utils/internal.py:193

        instance: The instance of a class
        include_properties: Whether to include properties in the result

    Usage:
        ```pycon
        >>> from supervision.utils.internal import get_instance_variables
        >>> import numpy as np
        >>> from supervision import Detections
        >>> detections = Detections(xyxy=np.array([[1, 2, 3, 4]]))
        >>> variables = get_instance_variables(detections)
        >>> 'xyxy' in variables
        True
        >>> 'data' in variables
        True

        ```
    """
    if isinstance(instance, type):
        raise ValueError("Only class instances are supported, not classes.")

    fields = {
        name
        for name, val in inspect.getmembers(instance)
        if not callable(val) and not name.startswith("_")
    }

    if not include_properties:
        properties = {
            name
            for name, val in inspect.getmembers(instance.__class__)
            if isinstance(val, property)
        }
        fields -= properties

    return fields

View on GitHub (pinned to 7f254d9784)

Solutions

  1. Pass an instance: get_instance_variables(Detections(xyxy=np.array([[1,2,3,4]]))).
  2. If you have the class, construct a minimal valid instance first.
  3. Audit call sites where the value may be either a class or an instance and branch on isinstance(x, type).

Example fix

// before
vars = get_instance_variables(sv.Detections)  # ValueError

// after
detections = sv.Detections(xyxy=np.array([[1, 2, 3, 4]]))
vars = get_instance_variables(detections)
Defensive patterns

Strategy: validation

Validate before calling

if isinstance(obj, type):
    raise ValueError(f'Expected an instance, got class {obj.__name__}')
variables = get_instance_variables(obj)

Type guard

def is_instance_not_class(obj: object) -> bool:
    return not isinstance(obj, type)

Try / catch

try:
    get_instance_variables(target)
except ValueError as e:
    if 'class instances' in str(e):
        target = target()  # instantiate with defaults if possible
    raise

Prevention

When it happens

Trigger: Calling get_instance_variables(Detections) or get_instance_variables(sv.BoxAnnotator) instead of get_instance_variables(detections) / get_instance_variables(box_annotator).

Common situations: Writing generic serialization or introspection tooling over supervision objects and forgetting to instantiate; passing a factory or class reference through a variable named `instance`; copy-paste from doctests that show the class name.

Related errors


AI-assisted analysis of roboflow/supervision@7f254d9784 (2026-08-15). Data as JSON: /api/errors/c27423b6c65940b6. Report an issue: GitHub.