{"record":{"id":"ccde87ede3479854","repo":"TheAlgorithms/Python","slug":"expecting-an-iterable-object-but-got-an-non-iterab","errorCode":null,"errorMessage":"Expecting an iterable object but got an non-iterable type {points}","messagePattern":"Expecting an iterable object but got an non-iterable type (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"divide_and_conquer/convex_hull.py","lineNumber":179,"sourceCode":"    >>> _validate_input([[1, 2]])\n    [(1.0, 2.0)]\n    >>> _validate_input([(1, 2)])\n    [(1.0, 2.0)]\n    >>> _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","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/divide_and_conquer/convex_hull.py#L161-L197","documentation":"Raised by _validate_input() in divide_and_conquer/convex_hull.py:179 when the points argument has no __iter__ attribute — i.e. passing a single scalar like an int, float, or None where an iterable of (x, y) points is required. It is the first of two validation stages: non-iterable raises this; an empty iterable raises the sibling 'Expecting a list of points' error.","triggerScenarios":"convex_hull(1), convex_hull(None), or convex_hull((3, 4)) where a single point tuple is passed instead of a collection of points — note a tuple IS iterable, so a lone point is accepted and misinterpreted, not rejected here.","commonSituations":"Calling the hull function with the result of a function that sometimes returns None (empty search), or unwrapping a list one level too many before passing it in.","solutions":["Always pass a collection of coordinate pairs: convex_hull([(x1,y1),(x2,y2),...])","Check for None explicitly before calling when the data source can return None","Guard with isinstance(points, (list, tuple)) and verify each element is a length-2 sequence"],"exampleFix":"// before\nhull = convex_hull(point)  # point = (3, 4) -> silently wrong; point = 3 -> ValueError\n\n# after\npoints = [point] if isinstance(point, tuple) and len(point) == 2 else point\nhull = convex_hull(points)","handlingStrategy":"type-guard","validationCode":"if points is None or isinstance(points, (int, float)):\n    raise ValueError('points must be an iterable of (x, y) pairs')\nhull = convex_hull(points)","typeGuard":"def is_points_collection(points) -> bool:\n    return hasattr(points, '__iter__') and len(points) > 0 and all(\n        hasattr(p, '__len__') and len(p) == 2 for p in points\n    )","tryCatchPattern":"try:\n    hull = convex_hull(points)\nexcept ValueError as e:\n    if 'non-iterable' not in str(e) and 'list of points' not in str(e):\n        raise\n    hull = None","preventionTips":["Check data sources for None before calling — the most common non-iterable input","A single (x, y) tuple passes the iterable check and is treated as 2 points of wrong shape; wrap it in a list first"],"tags":["computational-geometry","validation","type-guard","python"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}