From ce0cd52ce235d99a20cfa9d4d3c15747e3989123 Mon Sep 17 00:00:00 2001 From: RGBCube <78925721+RGBCube@users.noreply.github.com> Date: Sun, 26 Jun 2022 17:52:43 +0300 Subject: [PATCH] Fix some bugs in parser --- tools/unschema/__main__.py | 5 +---- tools/unschema/parser.py | 9 ++++++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/unschema/__main__.py b/tools/unschema/__main__.py index 7d5b5b9..028628d 100644 --- a/tools/unschema/__main__.py +++ b/tools/unschema/__main__.py @@ -57,11 +57,8 @@ else: end = time.perf_counter() - start - exit_code = os.system( + os.system( f"unimport {to} --gitignore -r --ignore-init; isort {to}; black {to}; flynt {to} -tc", ) - if exit_code != 0: - print(f"Formatting failed with exit code {exit_code}") - print(f"\n\nSuccess! Finished in {end*1000:.3} milliseconds") diff --git a/tools/unschema/parser.py b/tools/unschema/parser.py index b60c07c..18b326c 100644 --- a/tools/unschema/parser.py +++ b/tools/unschema/parser.py @@ -129,12 +129,15 @@ def generate( param_annotation = f"NotRequired[{param_annotation}]" if not no_comments: + examples = (', '.join(str(ex) for ex in exs)).replace("\n", "\\n") if (exs := value.get("examples")) else "" + + if (example := examples[:70]) != examples: + examples = f"{example}[...]" + typed_dict.extend( [ f" # Format: {fmt}" if (fmt := value.get("format")) else "", - f" # Example: {', '.join(str(ex) for ex in exs)}" - if (exs := value.get("examples")) - else "", + f" # Example: {examples}" ] )