# Buggy code
def add_directive_header(self, sig: str) -> None:
    super().add_directive_header(sig)
    sourcename = self.get_sourcename()
    if not self.options.annotation:
        # obtain annotation for this data
        try:
            annotations = get_type_hints(self.parent)
        except TypeError:
            annotations = {}

        if self.objpath[-1] in annotations:
            objrepr = stringify_typehint(annotations.get(self.objpath[-1]))
            self.add_line("   :type: " + objrepr, sourcename)
        else:
            key = (".".join(self.objpath[:-1]), self.objpath[-1])
            if self.analyzer and key in self.analyzer.annotations:
                self.add_line("   :type: " + self.analyzer.annotations[key], sourcename)

        try:
            if self.object is UNINITIALIZED_ATTR:
                pass
            else:
                objrepr = object_description(self.object)
                self.add_line("   :value: " + objrepr, sourcename)
        except ValueError:
            pass
    elif self.options.annotation is SUPPRESS:
        pass
    else:
        self.add_line("   :annotation: %s" % self.options.annotation, sourcename)


# Traceback (KeyError)
# Sphinx version: 3.2.0
# Python version: 3.8.5 (CPython)
# Docutils version: 0.16 release
# Jinja2 version: 2.11.2
# Last messages:
#   [new config]
#   8 added, 0 changed, 0 removed
#   reading sources... [ 12%] index
#   reading sources... [ 25%] misc
#   reading sources... [ 37%] ref_ast
#   reading sources... [ 50%] ref_containers
#   reading sources... [ 62%] ref_flow
#   reading sources... [ 75%] ref_fundamental
#   reading sources... [ 87%] ref_schedule
#   reading sources... [100%] reference
# Loaded extensions:
#   sphinx.ext.mathjax (3.2.0) from /var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/sphinx/ext/mathjax.py
#   sphinxcontrib.applehelp (1.0.2) from /var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/sphinxcontrib/applehelp/__init__.py
#   sphinxcontrib.devhelp (1.0.2) from /var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/sphinxcontrib/devhelp/__init__.py
#   sphinxcontrib.htmlhelp (1.0.3) from /var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/sphinxcontrib/htmlhelp/__init__.py
#   sphinxcontrib.serializinghtml (1.1.4) from /var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/sphinxcontrib/serializinghtml/__init__.py
#   sphinxcontrib.qthelp (1.0.3) from /var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/sphinxcontrib/qthelp/__init__.py
#   alabaster (0.7.12) from /var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/alabaster/__init__.py
#   sphinx.ext.autodoc.type_comment (3.2.0) from /var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/sphinx/ext/autodoc/type_comment.py
#   sphinx.ext.autodoc (3.2.0) from /var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/sphinx/ext/autodoc/__init__.py
#   sphinx.ext.intersphinx (3.2.0) from /var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/sphinx/ext/intersphinx.py
#   sphinx.ext.imgmath (3.2.0) from /var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/sphinx/ext/imgmath.py
Traceback (most recent call last):
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/sphinx/cmd/build.py", line 280, in build_main
app.build(args.force_all, filenames)
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/sphinx/application.py", line 348, in build
self.builder.build_update()
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/sphinx/builders/__init__.py", line 297, in build_update
self.build(to_build,
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/sphinx/builders/__init__.py", line 311, in build
updated_docnames = set(self.read())
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/sphinx/builders/__init__.py", line 418, in read
self._read_serial(docnames)
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/sphinx/builders/__init__.py", line 439, in _read_serial
self.read_doc(docname)
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/sphinx/builders/__init__.py", line 479, in read_doc
doctree = read_doc(self.app, self.env, self.env.doc2path(docname))
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/sphinx/io.py", line 223, in read_doc
pub.publish()
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/docutils/core.py", line 217, in publish
self.document = self.reader.read(self.source, self.parser,
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/sphinx/io.py", line 128, in read
self.parse()
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/docutils/readers/__init__.py", line 77, in parse
self.parser.parse(self.input, document)
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/sphinx/parsers.py", line 102, in parse
self.statemachine.run(inputlines, document, inliner=self.inliner)
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 170, in run
results = StateMachineWS.run(self, input_lines, input_offset,
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/docutils/statemachine.py", line 241, in run
context, next_state, result = self.check_line(
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/docutils/statemachine.py", line 459, in check_line
return method(match, context, next_state)
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 2769, in underline
self.section(title, source, style, lineno - 1, messages)
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 327, in section
self.new_subsection(title, lineno, messages)
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 393, in new_subsection
newabsoffset = self.nested_parse(
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 281, in nested_parse
state_machine.run(block, input_offset, memo=self.memo,
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 196, in run
results = StateMachineWS.run(self, input_lines, input_offset)
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/docutils/statemachine.py", line 241, in run
context, next_state, result = self.check_line(
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/docutils/statemachine.py", line 459, in check_line
return method(match, context, next_state)
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 2769, in underline
self.section(title, source, style, lineno - 1, messages)
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 327, in section
self.new_subsection(title, lineno, messages)
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 393, in new_subsection
newabsoffset = self.nested_parse(
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 281, in nested_parse
state_machine.run(block, input_offset, memo=self.memo,
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 196, in run
results = StateMachineWS.run(self, input_lines, input_offset)
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/docutils/statemachine.py", line 241, in run
context, next_state, result = self.check_line(
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/docutils/statemachine.py", line 459, in check_line
return method(match, context, next_state)
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 2342, in explicit_markup
nodelist, blank_finish = self.explicit_construct(match)
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 2354, in explicit_construct
return method(self, expmatch)
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 2096, in directive
return self.run_directive(
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 2146, in run_directive
result = directive_instance.run()
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/sphinx/ext/autodoc/directive.py", line 146, in run
documenter.generate(more_content=self.content)
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/sphinx/ext/autodoc/__init__.py", line 1568, in generate
return super().generate(more_content=more_content,
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/sphinx/ext/autodoc/__init__.py", line 894, in generate
self.document_members(all_members)
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/sphinx/ext/autodoc/__init__.py", line 1559, in document_members
super().document_members(all_members)
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/sphinx/ext/autodoc/__init__.py", line 775, in document_members
documenter.generate(
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/sphinx/ext/autodoc/__init__.py", line 884, in generate
self.add_directive_header(sig)
File "/var/lib/gitlab-runner/builds/0d8732fb/0/inducer/islpy/.env/lib/python3.8/site-packages/sphinx/ext/autodoc/__init__.py", line 1980, in add_directive_header
annotations = get_type_hints(self.parent)
File "/usr/lib/python3.8/typing.py", line 1223, in get_type_hints
base_globals = sys.modules[base.__module__].__dict__
KeyError: 'pybind11_builtins'

# Fixed code
def add_directive_header(self, sig: str) -> None:
    super().add_directive_header(sig)
    sourcename = self.get_sourcename()
    if not self.options.annotation:
        # obtain annotation for this data
        try:
            annotations = get_type_hints(self.parent)
        except TypeError:
            annotations = {}
        except KeyError:
            # a broken class found (refs: https://github.com/sphinx-doc/sphinx/issues/8084)
            annotations = {}

        if self.objpath[-1] in annotations:
            objrepr = stringify_typehint(annotations.get(self.objpath[-1]))
            self.add_line("   :type: " + objrepr, sourcename)
        else:
            key = (".".join(self.objpath[:-1]), self.objpath[-1])
            if self.analyzer and key in self.analyzer.annotations:
                self.add_line("   :type: " + self.analyzer.annotations[key], sourcename)

        try:
            if self.object is UNINITIALIZED_ATTR:
                pass
            else:
                objrepr = object_description(self.object)
                self.add_line("   :value: " + objrepr, sourcename)
        except ValueError:
            pass
    elif self.options.annotation is SUPPRESS:
        pass
    else:
        self.add_line("   :annotation: %s" % self.options.annotation, sourcename)