Get desired shapes or raise an error.
(s: Shape, ts: Shapes | tuple[Shapes, ...])
| 5063 | |
| 5064 | |
| 5065 | def _get(s: Shape, ts: Shapes | tuple[Shapes, ...]) -> Iterable[Shape]: |
| 5066 | """ |
| 5067 | Get desired shapes or raise an error. |
| 5068 | """ |
| 5069 | |
| 5070 | # convert input into tuple |
| 5071 | if isinstance(ts, tuple): |
| 5072 | types = ts |
| 5073 | else: |
| 5074 | types = (ts,) |
| 5075 | |
| 5076 | # validate the underlying shape, compounds are unpacked |
| 5077 | t = s.ShapeType() |
| 5078 | |
| 5079 | if t in types: |
| 5080 | yield s |
| 5081 | elif t == "Compound": |
| 5082 | for el in s: |
| 5083 | if el.ShapeType() in ts: |
| 5084 | yield el |
| 5085 | else: |
| 5086 | raise ValueError( |
| 5087 | f"Required type(s): {types}; encountered {el.ShapeType()}" |
| 5088 | ) |
| 5089 | else: |
| 5090 | raise ValueError(f"Required type(s): {types}; encountered {t}") |
| 5091 | |
| 5092 | |
| 5093 | def _get_one(s: Shape, ts: Shapes | tuple[Shapes, ...]) -> Shape: |