Skip to content

Commit f014783

Browse files
authored
Point to precise line in parsed source for parsing problems (#10)
* Point to precise line in parsed source for grammar errors * Refactor to new _get_docstring_node with tests * Show file & context for unknown doctypes * Improve escape_qualname Collapse multiple replaced special chars to one "_" and add doctests. * Don't prefix with _UnknownName_ Instead just alias to typing.Any. This should make it a bit easier to addopt docstub gradually. * Refactor to `doctype_to_annotation` avoids confusion with the parent classes `transform` method. * Fix tests for DoctypeTransformer * Show unknown name in error message * Don't swallow SystemExit or KeyboardInterrupt * Expand docstring of accumulate_qualname * Use bold red to underline reported errors * Ignore path delimiter in doctest to support Windows Otherwise, this fails on Windows which returns "file\\with\\..." * Make arguments to DoctypeTransformer optional This makes it easier to test the class. * Test DoctypeTransformer for unknown names * Use "Any" instead of "_GrammarError_" * Don't print in DocstringAnnotations if ctx=None Also add a few tests for that class and remove the currently unused yields property. * Add tests for Annotation class * Extend doctest of ContextFormatter
1 parent 376e026 commit f014783

8 files changed

Lines changed: 654 additions & 147 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ ignore = [
8787
"ISC001", # Conflicts with formatter
8888
"RET504", # Assignment before `return` statement facilitates debugging
8989
"PTH123", # Using builtin open() instead of Path.open() is fine
90+
"SIM108", # Terniary operator is always more readable
9091
]
9192

9293

src/docstub/_cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ def main(source_dir, out_dir, config_path, verbose):
124124
stub_content = stub_transformer.python_to_stub(
125125
py_content, module_path=source_path
126126
)
127+
except (SystemExit, KeyboardInterrupt):
128+
raise
127129
except Exception as e:
128130
logger.exception("failed creating stub for %s:\n\n%s", source_path, e)
129131
continue

0 commit comments

Comments
 (0)