Download fixtures/pattern_lab/src/registry.py from tailot/codex-python: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/datasets/tailot/codex-python/resolve/main/fixtures/pattern_lab/src/registry.py
- Command line
-
hf download hf://datasets/tailot/codex-python/fixtures/pattern_lab/src/registry.py
-
curl -L -o registry.py https://huggingface.co/datasets/tailot/codex-python/resolve/main/fixtures/pattern_lab/src/registry.py
1.05 kB
| """Formatting handlers picked by a kind name. | |
| The first dispatcher is a chain of equality tests that each return a call, which is the | |
| shape the registry pattern rewrites. The second one is not: its branches do not take the | |
| same arguments, and its last branch returns instead of raising, so the pattern has to | |
| refuse it. | |
| """ | |
| def format_short(item): | |
| return str(item) | |
| def format_long(item): | |
| return "%s (%s)" % (item, type(item).__name__) | |
| def format_json(item): | |
| return sorted(str(part) for part in item) | |
| def format_labelled(item, label): | |
| return "%s: %s" % (label, item) | |
| def render(kind, item): | |
| if kind == "short": | |
| return format_short(item) | |
| elif kind == "long": | |
| return format_long(item) | |
| elif kind == "json": | |
| return format_json(item) | |
| else: | |
| raise ValueError("unsupported kind") | |
| def render_pair(kind, item, label): | |
| if kind == "short": | |
| return format_short(item) | |
| elif kind == "labelled": | |
| return format_labelled(item, label) | |
| else: | |
| return None | |