| 551 | raise KeyError(key) |
| 552 | |
| 553 | def __len__(self) -> int: |
| 554 | # NOTE: this will double-count keys that are duplicated between layers, so it's |
| 555 | # possible that `len(hlg) > len(hlg.to_dict())`. However, duplicate keys should |
| 556 | # not occur through normal use, and their existence would usually be a bug. |
| 557 | # So we ignore this case in favor of better performance. |
| 558 | # https://github.com/dask/dask/issues/7271 |
| 559 | return sum(len(layer) for layer in self.layers.values()) |
| 560 | |
| 561 | def __iter__(self) -> Iterator[Key]: |
| 562 | return iter(self.to_dict()) |