{"record":{"id":"2a781fd3f0cd8944","repo":"TheAlgorithms/Python","slug":"length-must-be-a-positive-numeric-value","errorCode":null,"errorMessage":"length must be a positive numeric value.","messagePattern":"length must be a positive numeric value\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"geometry/geometry.py","lineNumber":71,"sourceCode":"        ...\n    TypeError: length must be a positive numeric value.\n    >>> Side(5, None)\n    Traceback (most recent call last):\n        ...\n    TypeError: angle must be an Angle object.\n    >>> Side(5, Angle(90), \"Invalid next_side\")\n    Traceback (most recent call last):\n        ...\n    TypeError: next_side must be a Side or None.\n    \"\"\"\n\n    length: float\n    angle: Angle = field(default_factory=Angle)\n    next_side: Side | None = None\n\n    def __post_init__(self) -> None:\n        if not isinstance(self.length, (int, float)) or self.length <= 0:\n            raise TypeError(\"length must be a positive numeric value.\")\n        if not isinstance(self.angle, Angle):\n            raise TypeError(\"angle must be an Angle object.\")\n        if not isinstance(self.next_side, (Side, NoneType)):\n            raise TypeError(\"next_side must be a Side or None.\")\n\n\n@dataclass\nclass Ellipse:\n    \"\"\"\n    A geometric Ellipse on a 2D surface\n\n    >>> Ellipse(5, 10)\n    Ellipse(major_radius=5, minor_radius=10)\n    >>> Ellipse(5, 10) is Ellipse(5, 10)\n    False\n    >>> Ellipse(5, 10) == Ellipse(5, 10)\n    True\n    \"\"\"","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/geometry/geometry.py#L53-L89","documentation":"Raised by Side.__post_init__ in geometry/geometry.py when length is not int/float or is <= 0 (TypeError). A Side represents a polygon edge in meters; zero or negative lengths make perimeter/area math meaningless, so construction fails fast. As with Angle, TypeError is used for both type and range problems — unconventional but consistent within this module.","triggerScenarios":"Constructing Side(0), Side(-5), or Side('5'). Fired from __post_init__, i.e. at object creation, not when the side is later used in shape math.","commonSituations":"Zero-length sides from degenerate/duplicate consecutive vertices (common when simplifying polygons), sentinel defaults of 0, or numeric strings from imported geometry data.","solutions":["Pass a positive number: Side(5) or Side(2.5).","If the side comes from two vertices, check for duplicate vertices first — they produce length 0.","Convert numeric strings at the parse boundary."],"exampleFix":"# before\nimport math\nSide(math.dist(p1, p2))  # 0.0 when p1 == p2 after simplification\n\n# after\nlength = math.dist(p1, p2)\nif length <= 0:\n    raise ValueError(f'degenerate edge between {p1} and {p2}')\nSide(length)","handlingStrategy":"type-guard","validationCode":"if not isinstance(length, (int, float)) or isinstance(length, bool) or length <= 0:\n    raise TypeError('side length must be a positive number')\nSide(length)","typeGuard":"def is_valid_side_length(v: object) -> bool:\n    return isinstance(v, (int, float)) and not isinstance(v, bool) and v > 0","tryCatchPattern":"try:\n    s = Side(length)\nexcept TypeError as exc:\n    if 'positive numeric' in str(exc):\n        raise ValueError(f'degenerate side: {length}') from exc\n    raise","preventionTips":["Deduplicate consecutive vertices before building sides.","Catch TypeError for both bad type and bad range on Side/Angle in this module."],"tags":["geometry","input-validation","typeerror","dataclass"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}