# Buggy code
def __init__(self, builder: Builder, template_dir: str) -> None:
    loader = None  # type: BaseLoader
    template_dirs = [os.path.join(package_dir, "ext", "autosummary", "templates")]
    if builder is None:
        if template_dir:
            template_dirs.insert(0, template_dir)
        loader = FileSystemLoader(template_dirs)
    else:
        # allow the user to override the templates
        loader = BuiltinTemplateLoader()
        loader.init(builder, dirs=template_dirs)

    self.env = SandboxedEnvironment(loader=loader)
    self.env.filters["escape"] = rst.escape
    self.env.filters["e"] = rst.escape
    self.env.filters["underline"] = _underline

    if builder:
        if builder.app.translator:
            self.env.add_extension("jinja2.ext.i18n")
            self.env.install_gettext_translations(builder.app.translator)  # type: ignore


# Traceback (jinja2.exceptions.TemplateNotFound)
$ sphinx-autogen -t . 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 495, in main
generate_autosummary_docs(args.source_file, args.output_dir,
File "/Users/tkomiya/work/sphinx/sphinx/ext/autosummary/generate.py", line 290, 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 231, in generate_autosummary_content
return template.render(template_name, ns)
File "/Users/tkomiya/work/sphinx/sphinx/ext/autosummary/generate.py", line 142, 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 "./autosummary/module.rst", line 1, in top-level template code
{% extends "!autosummary/module.rst" %}
File "/Users/tkomiya/.pyenv/versions/3.8.1/lib/python3.8/site-packages/Jinja2-3.0.0a1-py3.8.egg/jinja2/loaders.py", line 189, in get_source
raise TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: !autosummary/module.rst

# Fixed code
def __init__(self, builder: Builder, template_dir: str = None) -> None:
    if template_dir:
        warnings.warn(
            "template_dir argument for AutosummaryRenderer is deprecated.",
            RemovedInSphinx50Warning,
        )

    system_templates_path = [
        os.path.join(package_dir, "ext", "autosummary", "templates")
    ]
    loader = SphinxTemplateLoader(
        builder.srcdir, builder.config.templates_path, system_templates_path
    )

    self.env = SandboxedEnvironment(loader=loader)
    self.env.filters["escape"] = rst.escape
    self.env.filters["e"] = rst.escape
    self.env.filters["underline"] = _underline

    if builder:
        if builder.app.translator:
            self.env.add_extension("jinja2.ext.i18n")
            self.env.install_gettext_translations(builder.app.translator)  # type: ignore