Validate the format of a dask key. See Also -------- iskey
(key: object)
| 170 | |
| 171 | |
| 172 | def validate_key(key: object) -> None: |
| 173 | """Validate the format of a dask key. |
| 174 | |
| 175 | See Also |
| 176 | -------- |
| 177 | iskey |
| 178 | """ |
| 179 | if iskey(key): |
| 180 | return |
| 181 | typ = type(key) |
| 182 | |
| 183 | if typ is tuple: |
| 184 | index = None |
| 185 | try: |
| 186 | for index, part in enumerate(cast(tuple, key)): # noqa: B007 |
| 187 | validate_key(part) |
| 188 | except TypeError as e: |
| 189 | raise TypeError( |
| 190 | f"Composite key contains unexpected key type at {index=} ({key=!r})" |
| 191 | ) from e |
| 192 | raise TypeError(f"Unexpected key type {typ} ({key=!r})") |
| 193 | |
| 194 | |
| 195 | @overload |