Check that the `inclusive` argument is among {"both", "neither", "left", "right"}. Parameters ---------- inclusive : {"both", "neither", "left", "right"} Returns ------- left_right_inclusive : tuple[bool, bool] Raises ------ ValueError : if argument is not
(inclusive: str | None)
| 422 | |
| 423 | |
| 424 | def validate_inclusive(inclusive: str | None) -> tuple[bool, bool]: |
| 425 | """ |
| 426 | Check that the `inclusive` argument is among {"both", "neither", "left", "right"}. |
| 427 | |
| 428 | Parameters |
| 429 | ---------- |
| 430 | inclusive : {"both", "neither", "left", "right"} |
| 431 | |
| 432 | Returns |
| 433 | ------- |
| 434 | left_right_inclusive : tuple[bool, bool] |
| 435 | |
| 436 | Raises |
| 437 | ------ |
| 438 | ValueError : if argument is not among valid values |
| 439 | """ |
| 440 | left_right_inclusive: tuple[bool, bool] | None = None |
| 441 | |
| 442 | if isinstance(inclusive, str): |
| 443 | left_right_inclusive = { |
| 444 | "both": (True, True), |
| 445 | "left": (True, False), |
| 446 | "right": (False, True), |
| 447 | "neither": (False, False), |
| 448 | }.get(inclusive) |
| 449 | |
| 450 | if left_right_inclusive is None: |
| 451 | raise ValueError( |
| 452 | "Inclusive has to be either 'both', 'neither', 'left' or 'right'" |
| 453 | ) |
| 454 | |
| 455 | return left_right_inclusive |
| 456 | |
| 457 | |
| 458 | def validate_insert_loc(loc: int, length: int) -> int: |