{"record":{"id":"2c04359fea77e0dc","repo":"TheAlgorithms/Python","slug":"expecting-a-list-of-points-but-got-points","errorCode":null,"errorMessage":"Expecting a list of points but got {points}","messagePattern":"Expecting a list of points but got (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"divide_and_conquer/convex_hull.py","lineNumber":183,"sourceCode":"    >>> _validate_input([Point(2, 1), Point(-1, 2)])\n    [(2.0, 1.0), (-1.0, 2.0)]\n    >>> _validate_input([])\n    Traceback (most recent call last):\n        ...\n    ValueError: Expecting a list of points but got []\n    >>> _validate_input(1)\n    Traceback (most recent call last):\n        ...\n    ValueError: Expecting an iterable object but got an non-iterable type 1\n    \"\"\"\n\n    if not hasattr(points, \"__iter__\"):\n        msg = f\"Expecting an iterable object but got an non-iterable type {points}\"\n        raise ValueError(msg)\n\n    if not points:\n        msg = f\"Expecting a list of points but got {points}\"\n        raise ValueError(msg)\n\n    return _construct_points(points)\n\n\ndef _det(a: Point, b: Point, c: Point) -> float:\n    \"\"\"\n    Computes the sign perpendicular distance of a 2d point c from a line segment\n    ab. The sign indicates the direction of c relative to ab.\n    A Positive value means c is above ab (to the left), while a negative value\n    means c is below ab (to the right). 0 means all three points are on a straight line.\n\n    As a side note, 0.5 * abs|det| is the area of triangle abc\n\n    Parameters\n    ----------\n    a: point, the point on the left end of line segment ab\n    b: point, the point on the right end of line segment ab\n    c: point, the point for which the direction and location is desired.","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/divide_and_conquer/convex_hull.py#L165-L201","documentation":"Raised by _validate_input in the convex hull module when the passed points object is iterable but empty (falsy). The function first requires an object with __iter__, then rejects anything that iterates to nothing, because a convex hull of zero points is undefined. This is a ValueError used to guard the divide-and-conquer hull algorithm from empty input.","triggerScenarios":"Calling the public convex hull entry point (e.g. convex_hull([]) or convex_hull(())) with an empty list/tuple, or with a generator/set that yields no elements. Note that a non-iterable argument raises the earlier 'Expecting an iterable object' error instead.","commonSituations":"Pipelines that read points from a file, database, or sensor feed that legitimately returns zero rows; filtering datasets before hull computation; passing an empty test fixture during unit testing.","solutions":["Check that the points collection is non-empty before calling the hull function: if points: hull = convex_hull(points).","Fix the upstream data source if empty input is unexpected (empty file path, wrong query, failed parse).","Wrap the call in try/except ValueError and treat empty input as a no-op hull if your use case allows it."],"exampleFix":"# before\nhull = convex_hull(points)  # points == [] raises ValueError\n\n# after\nif not points:\n    hull = []\nelse:\n    hull = convex_hull(points)","handlingStrategy":"validation","validationCode":"def has_points(points) -> bool:\n    return hasattr(points, '__iter__') and len(list(points)) > 0\n\nif has_points(points):\n    hull = convex_hull(points)","typeGuard":"def is_non_empty_points(points: object) -> bool:\n    return hasattr(points, '__iter__') and bool(list(points))","tryCatchPattern":"try:\n    hull = convex_hull(points)\nexcept ValueError as exc:\n    if 'list of points' in str(exc):\n        hull = []\n    else:\n        raise","preventionTips":["Check for empty collections before any geometric operation that needs at least one element.","Centralize empty-dataset handling at data-load time instead of deep inside algorithms.","Write unit tests covering the empty-input case for every geometry pipeline stage."],"tags":["python","input-validation","computational-geometry","divide-and-conquer"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}