Skip to content

Commit 7898bdd

Browse files
committed
Async: Group modification operations
1 parent 2a8c256 commit 7898bdd

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

script/generate_async.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,21 @@ def process(source: Path, target: Path):
9999
with Path.open(module_path) as fp:
100100
module_dump = fp.read()
101101

102-
module_dump = re.sub(r"( {4}def )(?!_)", r" async def ", module_dump)
103-
104-
module_dump = re.sub(r"self\.client\.(.+)\(", r"await self.client.\1(", module_dump)
105-
102+
# Adjust imports.
106103
for relative_import in [".base", "..client", "..knowledge", "..model"]:
107104
module_dump = module_dump.replace(f"from {relative_import}", f"from .{relative_import}")
108105

109-
module_dump = module_dump.replace("self.api.version", "await self.api.version")
106+
# Modify function definitions.
107+
module_dump = re.sub(r"( {4}def )(?!_)", r" async def ", module_dump)
108+
109+
# Modify function calls.
110+
module_dump = re.sub(r"self\.client\.(.+)\(", r"await self.client.\1(", module_dump)
110111
module_dump = re.sub(r"= self\.(.+)\(", r"= await self.\1(", module_dump)
111112
module_dump = re.sub(r"send_request\(", r"await send_request(", module_dump)
112113

114+
# Modify property accesses.
115+
module_dump = module_dump.replace("self.api.version", "await self.api.version")
116+
113117
module_processed.append(module_path)
114118
target_path = Path(str(module_path).replace(str(source), str(target)))
115119
with Path.open(target_path, "w") as fp:

0 commit comments

Comments
 (0)