Get one shape or raise an error.
(s: Shape, ts: Shapes | tuple[Shapes, ...])
| 5091 | |
| 5092 | |
| 5093 | def _get_one(s: Shape, ts: Shapes | tuple[Shapes, ...]) -> Shape: |
| 5094 | """ |
| 5095 | Get one shape or raise an error. |
| 5096 | """ |
| 5097 | |
| 5098 | # convert input into tuple |
| 5099 | if isinstance(ts, tuple): |
| 5100 | types = ts |
| 5101 | else: |
| 5102 | types = (ts,) |
| 5103 | |
| 5104 | # validate the underlying shape, compounds are unpacked |
| 5105 | t = s.ShapeType() |
| 5106 | |
| 5107 | if t in types: |
| 5108 | rv = s |
| 5109 | elif t == "Compound": |
| 5110 | for el in s: |
| 5111 | if el.ShapeType() in ts: |
| 5112 | rv = el |
| 5113 | break |
| 5114 | else: |
| 5115 | raise ValueError( |
| 5116 | f"Required type(s): {types}, encountered {el.ShapeType()}" |
| 5117 | ) |
| 5118 | else: |
| 5119 | raise ValueError(f"Required type(s): {types}; encountered {t}") |
| 5120 | |
| 5121 | return rv |
| 5122 | |
| 5123 | |
| 5124 | def _get_one_wire(s: Shape) -> Wire: |