We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
importlib.abc in Python 3.10
**Description of the issue**

In Python 3.10.0, the command `import cirq` fails with the error:

```
class InstrumentedFinder(importlib.abc.MetaPathFinder):
AttributeError: module 'importlib' has no attribute 'abc'. Did you mean: '_abc'? 
```

**Workaround**

If one imports `importlib.abc` prior to importing cirq, no error occurs:

```python
from importlib import abc
import cirq
```

**Suggestion**

Probably you should add `from importlib import abc` somewhere in the Сirq's code.

Searching on Google, I've found a similar issue in another project: [grpc/issues/26062](https://github.com/grpc/grpc/issues/26062)

**Cirq version**
0.13.1



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `cirq-core/cirq/_import.py`
Content:
```
1 # Copyright 2019 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 from typing import Any, Callable, List, Optional
16 
17 from contextlib import contextmanager
18 import importlib
19 import sys
20 
21 # Bug workaround: https://github.com/python/mypy/issues/1498
22 ModuleType = Any
23 
24 
25 class InstrumentedFinder(importlib.abc.MetaPathFinder):
26     """A module finder used to hook the python import statement."""
27 
28     def __init__(
29         self,
30         finder: Any,
31         module_name: str,
32         wrap_module: Callable[[ModuleType], Optional[ModuleType]],
33         after_exec: Callable[[ModuleType], None],
34     ):
35         """A module finder that uses an existing module finder to find a python
36         module spec and intercept the execution of matching modules.
37 
38         Replace finders in `sys.meta_path` with instances of this class to
39         instrument import statements.
40 
41         Args:
42             finder: The original module finder to wrap.
43             module_name: The fully qualified module name to instrument e.g.
44                 `'pkg.submodule'`.  Submodules of this are also instrumented.
45             wrap_module: A callback function that takes a module object before
46                 it is run and either modifies or replaces it before it is run.
47                 The module returned by this function will be executed.  If None
48                 is returned the module is not executed and may be executed
49                 later.
50             after_exec: A callback function that is called with the return value
51                 of `wrap_module` after that module was executed if `wrap_module`
52                 didn't return None.
53         """
54 
55         self.finder = finder
56         self.module_name = module_name
57         self.match_components: List[str] = []
58         if self.module_name:
59             self.match_components = self.module_name.split('.')
60         self.wrap_module = wrap_module
61         self.after_exec = after_exec
62 
63     def find_spec(self, fullname: str, path: Any = None, target: Any = None) -> Any:
64         components = fullname.split('.')
65         spec = self.finder.find_spec(fullname, path=path, target=target)
66         if spec is None:
67             return None
68         if components[: len(self.match_components)] == self.match_components:
69             spec = self.wrap_spec(spec)
70         return spec
71 
72     def wrap_spec(self, spec: Any) -> Any:
73         spec.loader = InstrumentedLoader(spec.loader, self.wrap_module, self.after_exec)
74         return spec
75 
76 
77 class InstrumentedLoader(importlib.abc.Loader):
78     """A module loader used to hook the python import statement."""
79 
80     def __init__(
81         self,
82         loader: Any,
83         wrap_module: Callable[[ModuleType], Optional[ModuleType]],
84         after_exec: Callable[[ModuleType], None],
85     ):
86         """A module loader that uses an existing module loader and intercepts
87         the execution of a module.
88 
89         Use `InstrumentedFinder` to instrument modules with instances of this
90         class.
91 
92         Args:
93             loader: The original module loader to wrap.
94             module_name: The fully qualified module name to instrument e.g.
95                 `'pkg.submodule'`.  Submodules of this are also instrumented.
96             wrap_module: A callback function that takes a module object before
97                 it is run and either modifies or replaces it before it is run.
98                 The module returned by this function will be executed.  If None
99                 is returned the module is not executed and may be executed
100                 later.
101             after_exec: A callback function that is called with the return value
102                 of `wrap_module` after that module was executed if `wrap_module`
103                 didn't return None.
104         """
105         self.loader = loader
106         self.wrap_module = wrap_module
107         self.after_exec = after_exec
108 
109     def create_module(self, spec: ModuleType) -> ModuleType:
110         return self.loader.create_module(spec)
111 
112     def exec_module(self, module: ModuleType) -> None:
113         module = self.wrap_module(module)
114         if module is not None:
115             self.loader.exec_module(module)
116             self.after_exec(module)
117 
118 
119 @contextmanager
120 def wrap_module_executions(
121     module_name: str,
122     wrap_func: Callable[[ModuleType], Optional[ModuleType]],
123     after_exec: Callable[[ModuleType], None] = lambda m: None,
124     assert_meta_path_unchanged: bool = True,
125 ):
126     """A context manager that hooks python's import machinery within the
127     context.
128 
129     `wrap_func` is called before executing the module called `module_name` and
130     any of its submodules.  The module returned by `wrap_func` will be executed.
131     """
132 
133     def wrap(finder: Any) -> Any:
134         if not hasattr(finder, 'find_spec'):
135             return finder
136         return InstrumentedFinder(finder, module_name, wrap_func, after_exec)
137 
138     new_meta_path = [wrap(finder) for finder in sys.meta_path]
139 
140     try:
141         orig_meta_path, sys.meta_path = sys.meta_path, new_meta_path
142         yield
143     finally:
144         if assert_meta_path_unchanged:
145             assert sys.meta_path == new_meta_path
146         sys.meta_path = orig_meta_path
147 
148 
149 @contextmanager
150 def delay_import(module_name: str):
151     """A context manager that allows the module or submodule named `module_name`
152     to be imported without the contents of the module executing until the
153     context manager exits.
154     """
155     delay = True
156     execute_list = []
157 
158     def wrap_func(module: ModuleType) -> Optional[ModuleType]:
159         if delay:
160             execute_list.append(module)
161             return None  # Don't allow the module to be executed yet
162         return module  # Now allow the module to be executed
163 
164     with wrap_module_executions(module_name, wrap_func):
165         importlib.import_module(module_name)
166 
167     yield  # Run the body of the context
168 
169     delay = False
170     for module in execute_list:
171         module.__loader__.exec_module(module)  # Calls back into wrap_func
172
```
--- 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/cirq-core/cirq/_import.py b/cirq-core/cirq/_import.py
--- a/cirq-core/cirq/_import.py
+++ b/cirq-core/cirq/_import.py
@@ -12,17 +12,18 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from typing import Any, Callable, List, Optional
+from typing import Any, Callable, cast, List, Optional
+from types import ModuleType
+from importlib.machinery import ModuleSpec
+from importlib.abc import Loader
 
 from contextlib import contextmanager
 import importlib
+from importlib import abc
 import sys
 
-# Bug workaround: https://github.com/python/mypy/issues/1498
-ModuleType = Any
 
-
-class InstrumentedFinder(importlib.abc.MetaPathFinder):
+class InstrumentedFinder(abc.MetaPathFinder):
     """A module finder used to hook the python import statement."""
 
     def __init__(
@@ -74,7 +75,7 @@
         return spec
 
 
-class InstrumentedLoader(importlib.abc.Loader):
+class InstrumentedLoader(abc.Loader):
     """A module loader used to hook the python import statement."""
 
     def __init__(
@@ -106,12 +107,12 @@
         self.wrap_module = wrap_module
         self.after_exec = after_exec
 
-    def create_module(self, spec: ModuleType) -> ModuleType:
+    def create_module(self, spec: ModuleSpec) -> ModuleType:
         return self.loader.create_module(spec)
 
     def exec_module(self, module: ModuleType) -> None:
-        module = self.wrap_module(module)
-        if module is not None:
+        wrapped_module = self.wrap_module(module)
+        if wrapped_module is not None:
             self.loader.exec_module(module)
             self.after_exec(module)
 
@@ -168,4 +169,5 @@
 
     delay = False
     for module in execute_list:
-        module.__loader__.exec_module(module)  # Calls back into wrap_func
+        if module.__loader__ is not None and hasattr(module.__loader__, 'exec_module'):
+            cast(Loader, module.__loader__).exec_module(module)  # Calls back into wrap_func

{"golden_diff": "diff --git a/cirq-core/cirq/_import.py b/cirq-core/cirq/_import.py\n--- a/cirq-core/cirq/_import.py\n+++ b/cirq-core/cirq/_import.py\n@@ -12,17 +12,18 @@\n # See the License for the specific language governing permissions and\n # limitations under the License.\n \n-from typing import Any, Callable, List, Optional\n+from typing import Any, Callable, cast, List, Optional\n+from types import ModuleType\n+from importlib.machinery import ModuleSpec\n+from importlib.abc import Loader\n \n from contextlib import contextmanager\n import importlib\n+from importlib import abc\n import sys\n \n-# Bug workaround: https://github.com/python/mypy/issues/1498\n-ModuleType = Any\n \n-\n-class InstrumentedFinder(importlib.abc.MetaPathFinder):\n+class InstrumentedFinder(abc.MetaPathFinder):\n     \"\"\"A module finder used to hook the python import statement.\"\"\"\n \n     def __init__(\n@@ -74,7 +75,7 @@\n         return spec\n \n \n-class InstrumentedLoader(importlib.abc.Loader):\n+class InstrumentedLoader(abc.Loader):\n     \"\"\"A module loader used to hook the python import statement.\"\"\"\n \n     def __init__(\n@@ -106,12 +107,12 @@\n         self.wrap_module = wrap_module\n         self.after_exec = after_exec\n \n-    def create_module(self, spec: ModuleType) -> ModuleType:\n+    def create_module(self, spec: ModuleSpec) -> ModuleType:\n         return self.loader.create_module(spec)\n \n     def exec_module(self, module: ModuleType) -> None:\n-        module = self.wrap_module(module)\n-        if module is not None:\n+        wrapped_module = self.wrap_module(module)\n+        if wrapped_module is not None:\n             self.loader.exec_module(module)\n             self.after_exec(module)\n \n@@ -168,4 +169,5 @@\n \n     delay = False\n     for module in execute_list:\n-        module.__loader__.exec_module(module)  # Calls back into wrap_func\n+        if module.__loader__ is not None and hasattr(module.__loader__, 'exec_module'):\n+            cast(Loader, module.__loader__).exec_module(module)  # Calls back into wrap_func\n", "issue": "importlib.abc in Python 3.10\n**Description of the issue**\r\n\r\nIn Python 3.10.0, the command `import cirq` fails with the error:\r\n\r\n```\r\nclass InstrumentedFinder(importlib.abc.MetaPathFinder):\r\nAttributeError: module 'importlib' has no attribute 'abc'. Did you mean: '_abc'? \r\n```\r\n\r\n**Workaround**\r\n\r\nIf one imports `importlib.abc` prior to importing cirq, no error occurs:\r\n\r\n```python\r\nfrom importlib import abc\r\nimport cirq\r\n```\r\n\r\n**Suggestion**\r\n\r\nProbably you should add `from importlib import abc` somewhere in the \u0421irq's code.\r\n\r\nSearching on Google, I've found a similar issue in another project: [grpc/issues/26062](https://github.com/grpc/grpc/issues/26062)\r\n\r\n**Cirq version**\r\n0.13.1\r\n\r\n\n", "before_files": [{"content": "# Copyright 2019 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\nfrom typing import Any, Callable, List, Optional\n\nfrom contextlib import contextmanager\nimport importlib\nimport sys\n\n# Bug workaround: https://github.com/python/mypy/issues/1498\nModuleType = Any\n\n\nclass InstrumentedFinder(importlib.abc.MetaPathFinder):\n    \"\"\"A module finder used to hook the python import statement.\"\"\"\n\n    def __init__(\n        self,\n        finder: Any,\n        module_name: str,\n        wrap_module: Callable[[ModuleType], Optional[ModuleType]],\n        after_exec: Callable[[ModuleType], None],\n    ):\n        \"\"\"A module finder that uses an existing module finder to find a python\n        module spec and intercept the execution of matching modules.\n\n        Replace finders in `sys.meta_path` with instances of this class to\n        instrument import statements.\n\n        Args:\n            finder: The original module finder to wrap.\n            module_name: The fully qualified module name to instrument e.g.\n                `'pkg.submodule'`.  Submodules of this are also instrumented.\n            wrap_module: A callback function that takes a module object before\n                it is run and either modifies or replaces it before it is run.\n                The module returned by this function will be executed.  If None\n                is returned the module is not executed and may be executed\n                later.\n            after_exec: A callback function that is called with the return value\n                of `wrap_module` after that module was executed if `wrap_module`\n                didn't return None.\n        \"\"\"\n\n        self.finder = finder\n        self.module_name = module_name\n        self.match_components: List[str] = []\n        if self.module_name:\n            self.match_components = self.module_name.split('.')\n        self.wrap_module = wrap_module\n        self.after_exec = after_exec\n\n    def find_spec(self, fullname: str, path: Any = None, target: Any = None) -> Any:\n        components = fullname.split('.')\n        spec = self.finder.find_spec(fullname, path=path, target=target)\n        if spec is None:\n            return None\n        if components[: len(self.match_components)] == self.match_components:\n            spec = self.wrap_spec(spec)\n        return spec\n\n    def wrap_spec(self, spec: Any) -> Any:\n        spec.loader = InstrumentedLoader(spec.loader, self.wrap_module, self.after_exec)\n        return spec\n\n\nclass InstrumentedLoader(importlib.abc.Loader):\n    \"\"\"A module loader used to hook the python import statement.\"\"\"\n\n    def __init__(\n        self,\n        loader: Any,\n        wrap_module: Callable[[ModuleType], Optional[ModuleType]],\n        after_exec: Callable[[ModuleType], None],\n    ):\n        \"\"\"A module loader that uses an existing module loader and intercepts\n        the execution of a module.\n\n        Use `InstrumentedFinder` to instrument modules with instances of this\n        class.\n\n        Args:\n            loader: The original module loader to wrap.\n            module_name: The fully qualified module name to instrument e.g.\n                `'pkg.submodule'`.  Submodules of this are also instrumented.\n            wrap_module: A callback function that takes a module object before\n                it is run and either modifies or replaces it before it is run.\n                The module returned by this function will be executed.  If None\n                is returned the module is not executed and may be executed\n                later.\n            after_exec: A callback function that is called with the return value\n                of `wrap_module` after that module was executed if `wrap_module`\n                didn't return None.\n        \"\"\"\n        self.loader = loader\n        self.wrap_module = wrap_module\n        self.after_exec = after_exec\n\n    def create_module(self, spec: ModuleType) -> ModuleType:\n        return self.loader.create_module(spec)\n\n    def exec_module(self, module: ModuleType) -> None:\n        module = self.wrap_module(module)\n        if module is not None:\n            self.loader.exec_module(module)\n            self.after_exec(module)\n\n\n@contextmanager\ndef wrap_module_executions(\n    module_name: str,\n    wrap_func: Callable[[ModuleType], Optional[ModuleType]],\n    after_exec: Callable[[ModuleType], None] = lambda m: None,\n    assert_meta_path_unchanged: bool = True,\n):\n    \"\"\"A context manager that hooks python's import machinery within the\n    context.\n\n    `wrap_func` is called before executing the module called `module_name` and\n    any of its submodules.  The module returned by `wrap_func` will be executed.\n    \"\"\"\n\n    def wrap(finder: Any) -> Any:\n        if not hasattr(finder, 'find_spec'):\n            return finder\n        return InstrumentedFinder(finder, module_name, wrap_func, after_exec)\n\n    new_meta_path = [wrap(finder) for finder in sys.meta_path]\n\n    try:\n        orig_meta_path, sys.meta_path = sys.meta_path, new_meta_path\n        yield\n    finally:\n        if assert_meta_path_unchanged:\n            assert sys.meta_path == new_meta_path\n        sys.meta_path = orig_meta_path\n\n\n@contextmanager\ndef delay_import(module_name: str):\n    \"\"\"A context manager that allows the module or submodule named `module_name`\n    to be imported without the contents of the module executing until the\n    context manager exits.\n    \"\"\"\n    delay = True\n    execute_list = []\n\n    def wrap_func(module: ModuleType) -> Optional[ModuleType]:\n        if delay:\n            execute_list.append(module)\n            return None  # Don't allow the module to be executed yet\n        return module  # Now allow the module to be executed\n\n    with wrap_module_executions(module_name, wrap_func):\n        importlib.import_module(module_name)\n\n    yield  # Run the body of the context\n\n    delay = False\n    for module in execute_list:\n        module.__loader__.exec_module(module)  # Calls back into wrap_func\n", "path": "cirq-core/cirq/_import.py"}], "after_files": [{"content": "# Copyright 2019 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\nfrom typing import Any, Callable, cast, List, Optional\nfrom types import ModuleType\nfrom importlib.machinery import ModuleSpec\nfrom importlib.abc import Loader\n\nfrom contextlib import contextmanager\nimport importlib\nfrom importlib import abc\nimport sys\n\n\nclass InstrumentedFinder(abc.MetaPathFinder):\n    \"\"\"A module finder used to hook the python import statement.\"\"\"\n\n    def __init__(\n        self,\n        finder: Any,\n        module_name: str,\n        wrap_module: Callable[[ModuleType], Optional[ModuleType]],\n        after_exec: Callable[[ModuleType], None],\n    ):\n        \"\"\"A module finder that uses an existing module finder to find a python\n        module spec and intercept the execution of matching modules.\n\n        Replace finders in `sys.meta_path` with instances of this class to\n        instrument import statements.\n\n        Args:\n            finder: The original module finder to wrap.\n            module_name: The fully qualified module name to instrument e.g.\n                `'pkg.submodule'`.  Submodules of this are also instrumented.\n            wrap_module: A callback function that takes a module object before\n                it is run and either modifies or replaces it before it is run.\n                The module returned by this function will be executed.  If None\n                is returned the module is not executed and may be executed\n                later.\n            after_exec: A callback function that is called with the return value\n                of `wrap_module` after that module was executed if `wrap_module`\n                didn't return None.\n        \"\"\"\n\n        self.finder = finder\n        self.module_name = module_name\n        self.match_components: List[str] = []\n        if self.module_name:\n            self.match_components = self.module_name.split('.')\n        self.wrap_module = wrap_module\n        self.after_exec = after_exec\n\n    def find_spec(self, fullname: str, path: Any = None, target: Any = None) -> Any:\n        components = fullname.split('.')\n        spec = self.finder.find_spec(fullname, path=path, target=target)\n        if spec is None:\n            return None\n        if components[: len(self.match_components)] == self.match_components:\n            spec = self.wrap_spec(spec)\n        return spec\n\n    def wrap_spec(self, spec: Any) -> Any:\n        spec.loader = InstrumentedLoader(spec.loader, self.wrap_module, self.after_exec)\n        return spec\n\n\nclass InstrumentedLoader(abc.Loader):\n    \"\"\"A module loader used to hook the python import statement.\"\"\"\n\n    def __init__(\n        self,\n        loader: Any,\n        wrap_module: Callable[[ModuleType], Optional[ModuleType]],\n        after_exec: Callable[[ModuleType], None],\n    ):\n        \"\"\"A module loader that uses an existing module loader and intercepts\n        the execution of a module.\n\n        Use `InstrumentedFinder` to instrument modules with instances of this\n        class.\n\n        Args:\n            loader: The original module loader to wrap.\n            module_name: The fully qualified module name to instrument e.g.\n                `'pkg.submodule'`.  Submodules of this are also instrumented.\n            wrap_module: A callback function that takes a module object before\n                it is run and either modifies or replaces it before it is run.\n                The module returned by this function will be executed.  If None\n                is returned the module is not executed and may be executed\n                later.\n            after_exec: A callback function that is called with the return value\n                of `wrap_module` after that module was executed if `wrap_module`\n                didn't return None.\n        \"\"\"\n        self.loader = loader\n        self.wrap_module = wrap_module\n        self.after_exec = after_exec\n\n    def create_module(self, spec: ModuleSpec) -> ModuleType:\n        return self.loader.create_module(spec)\n\n    def exec_module(self, module: ModuleType) -> None:\n        wrapped_module = self.wrap_module(module)\n        if wrapped_module is not None:\n            self.loader.exec_module(module)\n            self.after_exec(module)\n\n\n@contextmanager\ndef wrap_module_executions(\n    module_name: str,\n    wrap_func: Callable[[ModuleType], Optional[ModuleType]],\n    after_exec: Callable[[ModuleType], None] = lambda m: None,\n    assert_meta_path_unchanged: bool = True,\n):\n    \"\"\"A context manager that hooks python's import machinery within the\n    context.\n\n    `wrap_func` is called before executing the module called `module_name` and\n    any of its submodules.  The module returned by `wrap_func` will be executed.\n    \"\"\"\n\n    def wrap(finder: Any) -> Any:\n        if not hasattr(finder, 'find_spec'):\n            return finder\n        return InstrumentedFinder(finder, module_name, wrap_func, after_exec)\n\n    new_meta_path = [wrap(finder) for finder in sys.meta_path]\n\n    try:\n        orig_meta_path, sys.meta_path = sys.meta_path, new_meta_path\n        yield\n    finally:\n        if assert_meta_path_unchanged:\n            assert sys.meta_path == new_meta_path\n        sys.meta_path = orig_meta_path\n\n\n@contextmanager\ndef delay_import(module_name: str):\n    \"\"\"A context manager that allows the module or submodule named `module_name`\n    to be imported without the contents of the module executing until the\n    context manager exits.\n    \"\"\"\n    delay = True\n    execute_list = []\n\n    def wrap_func(module: ModuleType) -> Optional[ModuleType]:\n        if delay:\n            execute_list.append(module)\n            return None  # Don't allow the module to be executed yet\n        return module  # Now allow the module to be executed\n\n    with wrap_module_executions(module_name, wrap_func):\n        importlib.import_module(module_name)\n\n    yield  # Run the body of the context\n\n    delay = False\n    for module in execute_list:\n        if module.__loader__ is not None and hasattr(module.__loader__, 'exec_module'):\n            cast(Loader, module.__loader__).exec_module(module)  # Calls back into wrap_func\n", "path": "cirq-core/cirq/_import.py"}]}