We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Docs: Filter out TYPE_CHECKING from public docs
**Description of the issue**

The `TYPE_CHECKING` variable imported from `typing` shows up in API docs (example: https://github.com/quantumlib/Cirq/issues/5150). We should filter it out, since it's not part of the cirq API. Per @dabacon's [comment](https://github.com/quantumlib/Cirq/pull/5229#issuecomment-1093080151), we should be able to do this in `dev_tools/docs/build_api_docs.py`.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `dev_tools/docs/build_api_docs.py`
Content:
```
1 # Copyright 2021 The Cirq Developers
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     https://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 # ==============================================================================
15 """Tool to generate external api_docs for Cirq.
16 
17 In order to publish to our site, devsite runs two jobs for us: stable and nightly.
18 The stable one downloads the latest cirq release from pypi and uses that to generate the reference
19 API docs.
20 The nightly one downloads the latest cirq pre-release (pip install cirq --pre) and uses that to
21 generate the "nightly diff".
22 
23 This script needs to cater for both of these cases.
24 """
25 
26 import os
27 import types
28 
29 import networkx
30 from absl import app
31 from absl import flags
32 from tensorflow_docs.api_generator import doc_controls
33 from tensorflow_docs.api_generator import generate_lib
34 from tensorflow_docs.api_generator import public_api
35 
36 import cirq
37 import cirq_aqt
38 import cirq_google
39 import cirq_ionq
40 import cirq_pasqal
41 import cirq_rigetti
42 import cirq_web
43 
44 from cirq import _doc
45 
46 flags.DEFINE_string("output_dir", "docs/api_docs", "Where to output the docs")
47 
48 flags.DEFINE_string(
49     "code_url_prefix",
50     "https://github.com/quantumlib/Cirq/blob/master",
51     "The url prefix for links to code.",
52 )
53 
54 flags.DEFINE_bool("search_hints", True, "Include metadata search hints in the generated files")
55 
56 flags.DEFINE_string("site_path", "reference/python", "Path prefix in the _toc.yaml")
57 
58 FLAGS = flags.FLAGS
59 
60 
61 def filter_unwanted_inherited_methods(path, parent, children):
62     """Filter the unwanted inherited methods.
63 
64     CircuitDag inherits a lot of methods from `networkx.DiGraph` and `Graph`.
65     This filter removes these, as it creates a lot of noise in the API docs.
66     """
67     if parent.__name__ != "CircuitDag":
68         return children
69 
70     filtered_children = []
71     for name, obj in children:
72         if isinstance(obj, types.FunctionType):
73             if obj.__module__.startswith('cirq'):
74                 filtered_children.append((name, obj))
75     return filtered_children
76 
77 
78 def main(unused_argv):
79     generate_cirq()
80     generate_cirq_google()
81     generate_cirq_aqt()
82     generate_cirq_ionq()
83     generate_cirq_pasqal()
84     generate_cirq_rigetti()
85     generate_cirq_web()
86 
87 
88 def generate_cirq():
89     doc_generator = generate_lib.DocGenerator(
90         root_title="Cirq",
91         py_modules=[("cirq", cirq)],
92         base_dir=os.path.dirname(cirq.__file__),
93         code_url_prefix=FLAGS.code_url_prefix + "/cirq-core/cirq",
94         search_hints=FLAGS.search_hints,
95         site_path=FLAGS.site_path,
96         callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],
97         extra_docs=_doc.RECORDED_CONST_DOCS,
98     )
99     doc_controls.decorate_all_class_attributes(
100         doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]
101     )
102     doc_generator.build(output_dir=FLAGS.output_dir)
103 
104 
105 def generate_cirq_aqt():
106     doc_generator = generate_lib.DocGenerator(
107         root_title="Cirq-aqt",
108         py_modules=[("cirq_aqt", cirq_aqt)],
109         base_dir=os.path.dirname(cirq_aqt.__file__),
110         code_url_prefix=FLAGS.code_url_prefix + "/cirq-aqt/cirq_aqt",
111         search_hints=FLAGS.search_hints,
112         site_path=FLAGS.site_path,
113         callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],
114         extra_docs=_doc.RECORDED_CONST_DOCS,
115     )
116     doc_controls.decorate_all_class_attributes(
117         doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]
118     )
119 
120     doc_generator.build(output_dir=FLAGS.output_dir)
121 
122 
123 def generate_cirq_ionq():
124     doc_generator = generate_lib.DocGenerator(
125         root_title="Cirq_ionq",
126         py_modules=[("cirq_ionq", cirq_ionq)],
127         base_dir=os.path.dirname(cirq_ionq.__file__),
128         code_url_prefix=FLAGS.code_url_prefix + "/cirq-ionq/cirq_ionq",
129         search_hints=FLAGS.search_hints,
130         site_path=FLAGS.site_path,
131         callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],
132         extra_docs=_doc.RECORDED_CONST_DOCS,
133     )
134     doc_controls.decorate_all_class_attributes(
135         doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]
136     )
137 
138     doc_generator.build(output_dir=FLAGS.output_dir)
139 
140 
141 def generate_cirq_pasqal():
142     doc_generator = generate_lib.DocGenerator(
143         root_title="Cirq-pasqal",
144         py_modules=[("cirq_pasqal", cirq_pasqal)],
145         base_dir=os.path.dirname(cirq_pasqal.__file__),
146         code_url_prefix=FLAGS.code_url_prefix + "/cirq-pasqal/cirq_pasqal",
147         search_hints=FLAGS.search_hints,
148         site_path=FLAGS.site_path,
149         callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],
150         extra_docs=_doc.RECORDED_CONST_DOCS,
151     )
152     doc_controls.decorate_all_class_attributes(
153         doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]
154     )
155 
156     doc_generator.build(output_dir=FLAGS.output_dir)
157 
158 
159 def generate_cirq_rigetti():
160     doc_generator = generate_lib.DocGenerator(
161         root_title="Cirq_rigetti",
162         py_modules=[("cirq_rigetti", cirq_rigetti)],
163         base_dir=os.path.dirname(cirq_rigetti.__file__),
164         code_url_prefix=FLAGS.code_url_prefix + "/cirq-rigetti/cirq_rigetti",
165         search_hints=FLAGS.search_hints,
166         site_path=FLAGS.site_path,
167         callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],
168         extra_docs=_doc.RECORDED_CONST_DOCS,
169     )
170     doc_controls.decorate_all_class_attributes(
171         doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]
172     )
173 
174     doc_generator.build(output_dir=FLAGS.output_dir)
175 
176 
177 def generate_cirq_google():
178     doc_generator = generate_lib.DocGenerator(
179         root_title="Cirq-google",
180         py_modules=[("cirq_google", cirq_google)],
181         base_dir=os.path.dirname(cirq_google.__file__),
182         code_url_prefix=FLAGS.code_url_prefix + "/cirq-google/cirq_google",
183         search_hints=FLAGS.search_hints,
184         site_path=FLAGS.site_path,
185         callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],
186         private_map={
187             # Opt to not build docs for these paths for now since they error.
188             "cirq_google.cloud.quantum.QuantumEngineServiceClient": ["enums"],
189             "cirq_google.cloud.quantum_v1alpha1.QuantumEngineServiceClient": ["enums"],
190             "cirq_google.api": ["v1"],
191         },
192         extra_docs=_doc.RECORDED_CONST_DOCS,
193     )
194     doc_generator.build(output_dir=FLAGS.output_dir)
195 
196 
197 def generate_cirq_web():
198     doc_generator = generate_lib.DocGenerator(
199         root_title="Cirq_web",
200         py_modules=[("cirq_web", cirq_web)],
201         base_dir=os.path.dirname(cirq_web.__file__),
202         code_url_prefix=FLAGS.code_url_prefix + "/cirq-web/cirq_web",
203         search_hints=FLAGS.search_hints,
204         site_path=FLAGS.site_path,
205         callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],
206         extra_docs=_doc.RECORDED_CONST_DOCS,
207     )
208     doc_controls.decorate_all_class_attributes(
209         doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]
210     )
211 
212     doc_generator.build(output_dir=FLAGS.output_dir)
213 
214 
215 if __name__ == "__main__":
216     app.run(main)
217
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/dev_tools/docs/build_api_docs.py b/dev_tools/docs/build_api_docs.py
--- a/dev_tools/docs/build_api_docs.py
+++ b/dev_tools/docs/build_api_docs.py
@@ -75,6 +75,14 @@
     return filtered_children
 
 
+def filter_type_checking(path, parent, children):
+    filtered_children = []
+    for name, obj in children:
+        if name != 'TYPE_CHECKING':
+            filtered_children.append((name, obj))
+    return filtered_children
+
+
 def main(unused_argv):
     generate_cirq()
     generate_cirq_google()
@@ -93,7 +101,11 @@
         code_url_prefix=FLAGS.code_url_prefix + "/cirq-core/cirq",
         search_hints=FLAGS.search_hints,
         site_path=FLAGS.site_path,
-        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],
+        callbacks=[
+            public_api.local_definitions_filter,
+            filter_unwanted_inherited_methods,
+            filter_type_checking,
+        ],
         extra_docs=_doc.RECORDED_CONST_DOCS,
     )
     doc_controls.decorate_all_class_attributes(
@@ -110,7 +122,11 @@
         code_url_prefix=FLAGS.code_url_prefix + "/cirq-aqt/cirq_aqt",
         search_hints=FLAGS.search_hints,
         site_path=FLAGS.site_path,
-        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],
+        callbacks=[
+            public_api.local_definitions_filter,
+            filter_unwanted_inherited_methods,
+            filter_type_checking,
+        ],
         extra_docs=_doc.RECORDED_CONST_DOCS,
     )
     doc_controls.decorate_all_class_attributes(
@@ -128,7 +144,11 @@
         code_url_prefix=FLAGS.code_url_prefix + "/cirq-ionq/cirq_ionq",
         search_hints=FLAGS.search_hints,
         site_path=FLAGS.site_path,
-        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],
+        callbacks=[
+            public_api.local_definitions_filter,
+            filter_unwanted_inherited_methods,
+            filter_type_checking,
+        ],
         extra_docs=_doc.RECORDED_CONST_DOCS,
     )
     doc_controls.decorate_all_class_attributes(
@@ -146,7 +166,11 @@
         code_url_prefix=FLAGS.code_url_prefix + "/cirq-pasqal/cirq_pasqal",
         search_hints=FLAGS.search_hints,
         site_path=FLAGS.site_path,
-        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],
+        callbacks=[
+            public_api.local_definitions_filter,
+            filter_unwanted_inherited_methods,
+            filter_type_checking,
+        ],
         extra_docs=_doc.RECORDED_CONST_DOCS,
     )
     doc_controls.decorate_all_class_attributes(
@@ -164,7 +188,11 @@
         code_url_prefix=FLAGS.code_url_prefix + "/cirq-rigetti/cirq_rigetti",
         search_hints=FLAGS.search_hints,
         site_path=FLAGS.site_path,
-        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],
+        callbacks=[
+            public_api.local_definitions_filter,
+            filter_unwanted_inherited_methods,
+            filter_type_checking,
+        ],
         extra_docs=_doc.RECORDED_CONST_DOCS,
     )
     doc_controls.decorate_all_class_attributes(
@@ -182,7 +210,11 @@
         code_url_prefix=FLAGS.code_url_prefix + "/cirq-google/cirq_google",
         search_hints=FLAGS.search_hints,
         site_path=FLAGS.site_path,
-        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],
+        callbacks=[
+            public_api.local_definitions_filter,
+            filter_unwanted_inherited_methods,
+            filter_type_checking,
+        ],
         private_map={
             # Opt to not build docs for these paths for now since they error.
             "cirq_google.cloud.quantum.QuantumEngineServiceClient": ["enums"],
@@ -202,7 +234,11 @@
         code_url_prefix=FLAGS.code_url_prefix + "/cirq-web/cirq_web",
         search_hints=FLAGS.search_hints,
         site_path=FLAGS.site_path,
-        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],
+        callbacks=[
+            public_api.local_definitions_filter,
+            filter_unwanted_inherited_methods,
+            filter_type_checking,
+        ],
         extra_docs=_doc.RECORDED_CONST_DOCS,
     )
     doc_controls.decorate_all_class_attributes(

{"golden_diff": "diff --git a/dev_tools/docs/build_api_docs.py b/dev_tools/docs/build_api_docs.py\n--- a/dev_tools/docs/build_api_docs.py\n+++ b/dev_tools/docs/build_api_docs.py\n@@ -75,6 +75,14 @@\n     return filtered_children\n \n \n+def filter_type_checking(path, parent, children):\n+    filtered_children = []\n+    for name, obj in children:\n+        if name != 'TYPE_CHECKING':\n+            filtered_children.append((name, obj))\n+    return filtered_children\n+\n+\n def main(unused_argv):\n     generate_cirq()\n     generate_cirq_google()\n@@ -93,7 +101,11 @@\n         code_url_prefix=FLAGS.code_url_prefix + \"/cirq-core/cirq\",\n         search_hints=FLAGS.search_hints,\n         site_path=FLAGS.site_path,\n-        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],\n+        callbacks=[\n+            public_api.local_definitions_filter,\n+            filter_unwanted_inherited_methods,\n+            filter_type_checking,\n+        ],\n         extra_docs=_doc.RECORDED_CONST_DOCS,\n     )\n     doc_controls.decorate_all_class_attributes(\n@@ -110,7 +122,11 @@\n         code_url_prefix=FLAGS.code_url_prefix + \"/cirq-aqt/cirq_aqt\",\n         search_hints=FLAGS.search_hints,\n         site_path=FLAGS.site_path,\n-        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],\n+        callbacks=[\n+            public_api.local_definitions_filter,\n+            filter_unwanted_inherited_methods,\n+            filter_type_checking,\n+        ],\n         extra_docs=_doc.RECORDED_CONST_DOCS,\n     )\n     doc_controls.decorate_all_class_attributes(\n@@ -128,7 +144,11 @@\n         code_url_prefix=FLAGS.code_url_prefix + \"/cirq-ionq/cirq_ionq\",\n         search_hints=FLAGS.search_hints,\n         site_path=FLAGS.site_path,\n-        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],\n+        callbacks=[\n+            public_api.local_definitions_filter,\n+            filter_unwanted_inherited_methods,\n+            filter_type_checking,\n+        ],\n         extra_docs=_doc.RECORDED_CONST_DOCS,\n     )\n     doc_controls.decorate_all_class_attributes(\n@@ -146,7 +166,11 @@\n         code_url_prefix=FLAGS.code_url_prefix + \"/cirq-pasqal/cirq_pasqal\",\n         search_hints=FLAGS.search_hints,\n         site_path=FLAGS.site_path,\n-        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],\n+        callbacks=[\n+            public_api.local_definitions_filter,\n+            filter_unwanted_inherited_methods,\n+            filter_type_checking,\n+        ],\n         extra_docs=_doc.RECORDED_CONST_DOCS,\n     )\n     doc_controls.decorate_all_class_attributes(\n@@ -164,7 +188,11 @@\n         code_url_prefix=FLAGS.code_url_prefix + \"/cirq-rigetti/cirq_rigetti\",\n         search_hints=FLAGS.search_hints,\n         site_path=FLAGS.site_path,\n-        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],\n+        callbacks=[\n+            public_api.local_definitions_filter,\n+            filter_unwanted_inherited_methods,\n+            filter_type_checking,\n+        ],\n         extra_docs=_doc.RECORDED_CONST_DOCS,\n     )\n     doc_controls.decorate_all_class_attributes(\n@@ -182,7 +210,11 @@\n         code_url_prefix=FLAGS.code_url_prefix + \"/cirq-google/cirq_google\",\n         search_hints=FLAGS.search_hints,\n         site_path=FLAGS.site_path,\n-        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],\n+        callbacks=[\n+            public_api.local_definitions_filter,\n+            filter_unwanted_inherited_methods,\n+            filter_type_checking,\n+        ],\n         private_map={\n             # Opt to not build docs for these paths for now since they error.\n             \"cirq_google.cloud.quantum.QuantumEngineServiceClient\": [\"enums\"],\n@@ -202,7 +234,11 @@\n         code_url_prefix=FLAGS.code_url_prefix + \"/cirq-web/cirq_web\",\n         search_hints=FLAGS.search_hints,\n         site_path=FLAGS.site_path,\n-        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],\n+        callbacks=[\n+            public_api.local_definitions_filter,\n+            filter_unwanted_inherited_methods,\n+            filter_type_checking,\n+        ],\n         extra_docs=_doc.RECORDED_CONST_DOCS,\n     )\n     doc_controls.decorate_all_class_attributes(\n", "issue": "Docs: Filter out TYPE_CHECKING from public docs\n**Description of the issue**\r\n\r\nThe `TYPE_CHECKING` variable imported from `typing` shows up in API docs (example: https://github.com/quantumlib/Cirq/issues/5150). We should filter it out, since it's not part of the cirq API. Per @dabacon's [comment](https://github.com/quantumlib/Cirq/pull/5229#issuecomment-1093080151), we should be able to do this in `dev_tools/docs/build_api_docs.py`.\r\n\n", "before_files": [{"content": "# Copyright 2021 The Cirq Developers\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     https://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n# ==============================================================================\n\"\"\"Tool to generate external api_docs for Cirq.\n\nIn order to publish to our site, devsite runs two jobs for us: stable and nightly.\nThe stable one downloads the latest cirq release from pypi and uses that to generate the reference\nAPI docs.\nThe nightly one downloads the latest cirq pre-release (pip install cirq --pre) and uses that to\ngenerate the \"nightly diff\".\n\nThis script needs to cater for both of these cases.\n\"\"\"\n\nimport os\nimport types\n\nimport networkx\nfrom absl import app\nfrom absl import flags\nfrom tensorflow_docs.api_generator import doc_controls\nfrom tensorflow_docs.api_generator import generate_lib\nfrom tensorflow_docs.api_generator import public_api\n\nimport cirq\nimport cirq_aqt\nimport cirq_google\nimport cirq_ionq\nimport cirq_pasqal\nimport cirq_rigetti\nimport cirq_web\n\nfrom cirq import _doc\n\nflags.DEFINE_string(\"output_dir\", \"docs/api_docs\", \"Where to output the docs\")\n\nflags.DEFINE_string(\n    \"code_url_prefix\",\n    \"https://github.com/quantumlib/Cirq/blob/master\",\n    \"The url prefix for links to code.\",\n)\n\nflags.DEFINE_bool(\"search_hints\", True, \"Include metadata search hints in the generated files\")\n\nflags.DEFINE_string(\"site_path\", \"reference/python\", \"Path prefix in the _toc.yaml\")\n\nFLAGS = flags.FLAGS\n\n\ndef filter_unwanted_inherited_methods(path, parent, children):\n    \"\"\"Filter the unwanted inherited methods.\n\n    CircuitDag inherits a lot of methods from `networkx.DiGraph` and `Graph`.\n    This filter removes these, as it creates a lot of noise in the API docs.\n    \"\"\"\n    if parent.__name__ != \"CircuitDag\":\n        return children\n\n    filtered_children = []\n    for name, obj in children:\n        if isinstance(obj, types.FunctionType):\n            if obj.__module__.startswith('cirq'):\n                filtered_children.append((name, obj))\n    return filtered_children\n\n\ndef main(unused_argv):\n    generate_cirq()\n    generate_cirq_google()\n    generate_cirq_aqt()\n    generate_cirq_ionq()\n    generate_cirq_pasqal()\n    generate_cirq_rigetti()\n    generate_cirq_web()\n\n\ndef generate_cirq():\n    doc_generator = generate_lib.DocGenerator(\n        root_title=\"Cirq\",\n        py_modules=[(\"cirq\", cirq)],\n        base_dir=os.path.dirname(cirq.__file__),\n        code_url_prefix=FLAGS.code_url_prefix + \"/cirq-core/cirq\",\n        search_hints=FLAGS.search_hints,\n        site_path=FLAGS.site_path,\n        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],\n        extra_docs=_doc.RECORDED_CONST_DOCS,\n    )\n    doc_controls.decorate_all_class_attributes(\n        doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]\n    )\n    doc_generator.build(output_dir=FLAGS.output_dir)\n\n\ndef generate_cirq_aqt():\n    doc_generator = generate_lib.DocGenerator(\n        root_title=\"Cirq-aqt\",\n        py_modules=[(\"cirq_aqt\", cirq_aqt)],\n        base_dir=os.path.dirname(cirq_aqt.__file__),\n        code_url_prefix=FLAGS.code_url_prefix + \"/cirq-aqt/cirq_aqt\",\n        search_hints=FLAGS.search_hints,\n        site_path=FLAGS.site_path,\n        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],\n        extra_docs=_doc.RECORDED_CONST_DOCS,\n    )\n    doc_controls.decorate_all_class_attributes(\n        doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]\n    )\n\n    doc_generator.build(output_dir=FLAGS.output_dir)\n\n\ndef generate_cirq_ionq():\n    doc_generator = generate_lib.DocGenerator(\n        root_title=\"Cirq_ionq\",\n        py_modules=[(\"cirq_ionq\", cirq_ionq)],\n        base_dir=os.path.dirname(cirq_ionq.__file__),\n        code_url_prefix=FLAGS.code_url_prefix + \"/cirq-ionq/cirq_ionq\",\n        search_hints=FLAGS.search_hints,\n        site_path=FLAGS.site_path,\n        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],\n        extra_docs=_doc.RECORDED_CONST_DOCS,\n    )\n    doc_controls.decorate_all_class_attributes(\n        doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]\n    )\n\n    doc_generator.build(output_dir=FLAGS.output_dir)\n\n\ndef generate_cirq_pasqal():\n    doc_generator = generate_lib.DocGenerator(\n        root_title=\"Cirq-pasqal\",\n        py_modules=[(\"cirq_pasqal\", cirq_pasqal)],\n        base_dir=os.path.dirname(cirq_pasqal.__file__),\n        code_url_prefix=FLAGS.code_url_prefix + \"/cirq-pasqal/cirq_pasqal\",\n        search_hints=FLAGS.search_hints,\n        site_path=FLAGS.site_path,\n        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],\n        extra_docs=_doc.RECORDED_CONST_DOCS,\n    )\n    doc_controls.decorate_all_class_attributes(\n        doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]\n    )\n\n    doc_generator.build(output_dir=FLAGS.output_dir)\n\n\ndef generate_cirq_rigetti():\n    doc_generator = generate_lib.DocGenerator(\n        root_title=\"Cirq_rigetti\",\n        py_modules=[(\"cirq_rigetti\", cirq_rigetti)],\n        base_dir=os.path.dirname(cirq_rigetti.__file__),\n        code_url_prefix=FLAGS.code_url_prefix + \"/cirq-rigetti/cirq_rigetti\",\n        search_hints=FLAGS.search_hints,\n        site_path=FLAGS.site_path,\n        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],\n        extra_docs=_doc.RECORDED_CONST_DOCS,\n    )\n    doc_controls.decorate_all_class_attributes(\n        doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]\n    )\n\n    doc_generator.build(output_dir=FLAGS.output_dir)\n\n\ndef generate_cirq_google():\n    doc_generator = generate_lib.DocGenerator(\n        root_title=\"Cirq-google\",\n        py_modules=[(\"cirq_google\", cirq_google)],\n        base_dir=os.path.dirname(cirq_google.__file__),\n        code_url_prefix=FLAGS.code_url_prefix + \"/cirq-google/cirq_google\",\n        search_hints=FLAGS.search_hints,\n        site_path=FLAGS.site_path,\n        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],\n        private_map={\n            # Opt to not build docs for these paths for now since they error.\n            \"cirq_google.cloud.quantum.QuantumEngineServiceClient\": [\"enums\"],\n            \"cirq_google.cloud.quantum_v1alpha1.QuantumEngineServiceClient\": [\"enums\"],\n            \"cirq_google.api\": [\"v1\"],\n        },\n        extra_docs=_doc.RECORDED_CONST_DOCS,\n    )\n    doc_generator.build(output_dir=FLAGS.output_dir)\n\n\ndef generate_cirq_web():\n    doc_generator = generate_lib.DocGenerator(\n        root_title=\"Cirq_web\",\n        py_modules=[(\"cirq_web\", cirq_web)],\n        base_dir=os.path.dirname(cirq_web.__file__),\n        code_url_prefix=FLAGS.code_url_prefix + \"/cirq-web/cirq_web\",\n        search_hints=FLAGS.search_hints,\n        site_path=FLAGS.site_path,\n        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],\n        extra_docs=_doc.RECORDED_CONST_DOCS,\n    )\n    doc_controls.decorate_all_class_attributes(\n        doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]\n    )\n\n    doc_generator.build(output_dir=FLAGS.output_dir)\n\n\nif __name__ == \"__main__\":\n    app.run(main)\n", "path": "dev_tools/docs/build_api_docs.py"}], "after_files": [{"content": "# Copyright 2021 The Cirq Developers\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     https://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n# ==============================================================================\n\"\"\"Tool to generate external api_docs for Cirq.\n\nIn order to publish to our site, devsite runs two jobs for us: stable and nightly.\nThe stable one downloads the latest cirq release from pypi and uses that to generate the reference\nAPI docs.\nThe nightly one downloads the latest cirq pre-release (pip install cirq --pre) and uses that to\ngenerate the \"nightly diff\".\n\nThis script needs to cater for both of these cases.\n\"\"\"\n\nimport os\nimport types\n\nimport networkx\nfrom absl import app\nfrom absl import flags\nfrom tensorflow_docs.api_generator import doc_controls\nfrom tensorflow_docs.api_generator import generate_lib\nfrom tensorflow_docs.api_generator import public_api\n\nimport cirq\nimport cirq_aqt\nimport cirq_google\nimport cirq_ionq\nimport cirq_pasqal\nimport cirq_rigetti\nimport cirq_web\n\nfrom cirq import _doc\n\nflags.DEFINE_string(\"output_dir\", \"docs/api_docs\", \"Where to output the docs\")\n\nflags.DEFINE_string(\n    \"code_url_prefix\",\n    \"https://github.com/quantumlib/Cirq/blob/master\",\n    \"The url prefix for links to code.\",\n)\n\nflags.DEFINE_bool(\"search_hints\", True, \"Include metadata search hints in the generated files\")\n\nflags.DEFINE_string(\"site_path\", \"reference/python\", \"Path prefix in the _toc.yaml\")\n\nFLAGS = flags.FLAGS\n\n\ndef filter_unwanted_inherited_methods(path, parent, children):\n    \"\"\"Filter the unwanted inherited methods.\n\n    CircuitDag inherits a lot of methods from `networkx.DiGraph` and `Graph`.\n    This filter removes these, as it creates a lot of noise in the API docs.\n    \"\"\"\n    if parent.__name__ != \"CircuitDag\":\n        return children\n\n    filtered_children = []\n    for name, obj in children:\n        if isinstance(obj, types.FunctionType):\n            if obj.__module__.startswith('cirq'):\n                filtered_children.append((name, obj))\n    return filtered_children\n\n\ndef filter_type_checking(path, parent, children):\n    filtered_children = []\n    for name, obj in children:\n        if name != 'TYPE_CHECKING':\n            filtered_children.append((name, obj))\n    return filtered_children\n\n\ndef main(unused_argv):\n    generate_cirq()\n    generate_cirq_google()\n    generate_cirq_aqt()\n    generate_cirq_ionq()\n    generate_cirq_pasqal()\n    generate_cirq_rigetti()\n    generate_cirq_web()\n\n\ndef generate_cirq():\n    doc_generator = generate_lib.DocGenerator(\n        root_title=\"Cirq\",\n        py_modules=[(\"cirq\", cirq)],\n        base_dir=os.path.dirname(cirq.__file__),\n        code_url_prefix=FLAGS.code_url_prefix + \"/cirq-core/cirq\",\n        search_hints=FLAGS.search_hints,\n        site_path=FLAGS.site_path,\n        callbacks=[\n            public_api.local_definitions_filter,\n            filter_unwanted_inherited_methods,\n            filter_type_checking,\n        ],\n        extra_docs=_doc.RECORDED_CONST_DOCS,\n    )\n    doc_controls.decorate_all_class_attributes(\n        doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]\n    )\n    doc_generator.build(output_dir=FLAGS.output_dir)\n\n\ndef generate_cirq_aqt():\n    doc_generator = generate_lib.DocGenerator(\n        root_title=\"Cirq-aqt\",\n        py_modules=[(\"cirq_aqt\", cirq_aqt)],\n        base_dir=os.path.dirname(cirq_aqt.__file__),\n        code_url_prefix=FLAGS.code_url_prefix + \"/cirq-aqt/cirq_aqt\",\n        search_hints=FLAGS.search_hints,\n        site_path=FLAGS.site_path,\n        callbacks=[\n            public_api.local_definitions_filter,\n            filter_unwanted_inherited_methods,\n            filter_type_checking,\n        ],\n        extra_docs=_doc.RECORDED_CONST_DOCS,\n    )\n    doc_controls.decorate_all_class_attributes(\n        doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]\n    )\n\n    doc_generator.build(output_dir=FLAGS.output_dir)\n\n\ndef generate_cirq_ionq():\n    doc_generator = generate_lib.DocGenerator(\n        root_title=\"Cirq_ionq\",\n        py_modules=[(\"cirq_ionq\", cirq_ionq)],\n        base_dir=os.path.dirname(cirq_ionq.__file__),\n        code_url_prefix=FLAGS.code_url_prefix + \"/cirq-ionq/cirq_ionq\",\n        search_hints=FLAGS.search_hints,\n        site_path=FLAGS.site_path,\n        callbacks=[\n            public_api.local_definitions_filter,\n            filter_unwanted_inherited_methods,\n            filter_type_checking,\n        ],\n        extra_docs=_doc.RECORDED_CONST_DOCS,\n    )\n    doc_controls.decorate_all_class_attributes(\n        doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]\n    )\n\n    doc_generator.build(output_dir=FLAGS.output_dir)\n\n\ndef generate_cirq_pasqal():\n    doc_generator = generate_lib.DocGenerator(\n        root_title=\"Cirq-pasqal\",\n        py_modules=[(\"cirq_pasqal\", cirq_pasqal)],\n        base_dir=os.path.dirname(cirq_pasqal.__file__),\n        code_url_prefix=FLAGS.code_url_prefix + \"/cirq-pasqal/cirq_pasqal\",\n        search_hints=FLAGS.search_hints,\n        site_path=FLAGS.site_path,\n        callbacks=[\n            public_api.local_definitions_filter,\n            filter_unwanted_inherited_methods,\n            filter_type_checking,\n        ],\n        extra_docs=_doc.RECORDED_CONST_DOCS,\n    )\n    doc_controls.decorate_all_class_attributes(\n        doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]\n    )\n\n    doc_generator.build(output_dir=FLAGS.output_dir)\n\n\ndef generate_cirq_rigetti():\n    doc_generator = generate_lib.DocGenerator(\n        root_title=\"Cirq_rigetti\",\n        py_modules=[(\"cirq_rigetti\", cirq_rigetti)],\n        base_dir=os.path.dirname(cirq_rigetti.__file__),\n        code_url_prefix=FLAGS.code_url_prefix + \"/cirq-rigetti/cirq_rigetti\",\n        search_hints=FLAGS.search_hints,\n        site_path=FLAGS.site_path,\n        callbacks=[\n            public_api.local_definitions_filter,\n            filter_unwanted_inherited_methods,\n            filter_type_checking,\n        ],\n        extra_docs=_doc.RECORDED_CONST_DOCS,\n    )\n    doc_controls.decorate_all_class_attributes(\n        doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]\n    )\n\n    doc_generator.build(output_dir=FLAGS.output_dir)\n\n\ndef generate_cirq_google():\n    doc_generator = generate_lib.DocGenerator(\n        root_title=\"Cirq-google\",\n        py_modules=[(\"cirq_google\", cirq_google)],\n        base_dir=os.path.dirname(cirq_google.__file__),\n        code_url_prefix=FLAGS.code_url_prefix + \"/cirq-google/cirq_google\",\n        search_hints=FLAGS.search_hints,\n        site_path=FLAGS.site_path,\n        callbacks=[\n            public_api.local_definitions_filter,\n            filter_unwanted_inherited_methods,\n            filter_type_checking,\n        ],\n        private_map={\n            # Opt to not build docs for these paths for now since they error.\n            \"cirq_google.cloud.quantum.QuantumEngineServiceClient\": [\"enums\"],\n            \"cirq_google.cloud.quantum_v1alpha1.QuantumEngineServiceClient\": [\"enums\"],\n            \"cirq_google.api\": [\"v1\"],\n        },\n        extra_docs=_doc.RECORDED_CONST_DOCS,\n    )\n    doc_generator.build(output_dir=FLAGS.output_dir)\n\n\ndef generate_cirq_web():\n    doc_generator = generate_lib.DocGenerator(\n        root_title=\"Cirq_web\",\n        py_modules=[(\"cirq_web\", cirq_web)],\n        base_dir=os.path.dirname(cirq_web.__file__),\n        code_url_prefix=FLAGS.code_url_prefix + \"/cirq-web/cirq_web\",\n        search_hints=FLAGS.search_hints,\n        site_path=FLAGS.site_path,\n        callbacks=[\n            public_api.local_definitions_filter,\n            filter_unwanted_inherited_methods,\n            filter_type_checking,\n        ],\n        extra_docs=_doc.RECORDED_CONST_DOCS,\n    )\n    doc_controls.decorate_all_class_attributes(\n        doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]\n    )\n\n    doc_generator.build(output_dir=FLAGS.output_dir)\n\n\nif __name__ == \"__main__\":\n    app.run(main)\n", "path": "dev_tools/docs/build_api_docs.py"}]}