Skip to content

Commit 9ce0645

Browse files
committed
Async: Group modification operations
1 parent 2ce4de3 commit 9ce0645

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
@@ -97,17 +97,21 @@ def process(source: Path, target: Path):
9797
with Path.open(module_path) as fp:
9898
module_dump = fp.read()
9999

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

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

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

0 commit comments

Comments
 (0)