# Buggy code
def main(argv: List[str] = sys.argv[1:]) -> None:
    sphinx.locale.setlocale(locale.LC_ALL, "")
    sphinx.locale.init_console(os.path.join(package_dir, "locale"), "sphinx")

    app = DummyApplication()
    logging.setup(app, sys.stdout, sys.stderr)  # type: ignore
    setup_documenters(app)
    args = get_parser().parse_args(argv)
    builder = DummyBuilder(app, args.templates)
    generate_autosummary_docs(
        args.source_file,
        args.output_dir,
        "." + args.suffix,
        builder=builder,  # type: ignore
        imported_members=args.imported_members,
        app=app,
    )


# Traceback (jinja2.exceptions.UndefinedError)
$ sphinx-autogen example.py
[autosummary] example.py の autosummary を生成中
Traceback (most recent call last):
File "/Users/tkomiya/work/tmp/bin/sphinx-autogen", line 11, in <module>
load_entry_point('Sphinx', 'console_scripts', 'sphinx-autogen')()
File "/Users/tkomiya/work/sphinx/sphinx/ext/autosummary/generate.py", line 517, in main
generate_autosummary_docs(args.source_file, args.output_dir,
File "/Users/tkomiya/work/sphinx/sphinx/ext/autosummary/generate.py", line 304, in generate_autosummary_docs
content = generate_autosummary_content(name, obj, parent, template, entry.template,
File "/Users/tkomiya/work/sphinx/sphinx/ext/autosummary/generate.py", line 245, in generate_autosummary_content
return template.render(template_name, ns)
File "/Users/tkomiya/work/sphinx/sphinx/ext/autosummary/generate.py", line 144, in render
return self.env.get_template(template_name).render(context)
File "/Users/tkomiya/.pyenv/versions/3.8.1/lib/python3.8/site-packages/Jinja2-3.0.0a1-py3.8.egg/jinja2/environment.py", line 1045, in render
self.environment.handle_exception()
File "/Users/tkomiya/.pyenv/versions/3.8.1/lib/python3.8/site-packages/Jinja2-3.0.0a1-py3.8.egg/jinja2/environment.py", line 787, in handle_exception
raise rewrite_traceback_stack(source=source)
File "/Users/tkomiya/work/sphinx/sphinx/ext/autosummary/templates/autosummary/module.rst", line 5, in top-level template code
{% block functions %}
File "/Users/tkomiya/work/sphinx/sphinx/ext/autosummary/templates/autosummary/module.rst", line 7, in block 'functions'
.. rubric:: {{ _('Functions') }}
File "/Users/tkomiya/.pyenv/versions/3.8.1/lib/python3.8/site-packages/Jinja2-3.0.0a1-py3.8.egg/jinja2/sandbox.py", line 410, in call
if not __self.is_safe_callable(__obj):
File "/Users/tkomiya/.pyenv/versions/3.8.1/lib/python3.8/site-packages/Jinja2-3.0.0a1-py3.8.egg/jinja2/sandbox.py", line 310, in is_safe_callable
getattr(obj, "unsafe_callable", False) or getattr(obj, "alters_data", False)
jinja2.exceptions.UndefinedError: '_' is undefined

# Fixed code
def main(argv: List[str] = sys.argv[1:]) -> None:
    sphinx.locale.setlocale(locale.LC_ALL, "")
    sphinx.locale.init_console(os.path.join(package_dir, "locale"), "sphinx")
    translator, _ = sphinx.locale.init([], None)

    app = DummyApplication(translator)
    logging.setup(app, sys.stdout, sys.stderr)  # type: ignore
    setup_documenters(app)
    args = get_parser().parse_args(argv)
    builder = DummyBuilder(app, args.templates)
    generate_autosummary_docs(
        args.source_file,
        args.output_dir,
        "." + args.suffix,
        builder=builder,  # type: ignore
        imported_members=args.imported_members,
        app=app,
    )