-
Notifications
You must be signed in to change notification settings - Fork 37
Refactor async generator #226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -99,17 +99,21 @@ def process(source: Path, target: Path): | |||||||||||||
with Path.open(module_path) as fp: | ||||||||||||||
module_dump = fp.read() | ||||||||||||||
|
||||||||||||||
module_dump = re.sub(r"( {4}def )(?!_)", r" async def ", module_dump) | ||||||||||||||
|
||||||||||||||
module_dump = re.sub(r"self\.client\.(.+)\(", r"await self.client.\1(", module_dump) | ||||||||||||||
|
||||||||||||||
# Adjust imports. | ||||||||||||||
for relative_import in [".base", "..client", "..knowledge", "..model"]: | ||||||||||||||
module_dump = module_dump.replace(f"from {relative_import}", f"from .{relative_import}") | ||||||||||||||
|
||||||||||||||
module_dump = module_dump.replace("self.api.version", "await self.api.version") | ||||||||||||||
# Modify function definitions. | ||||||||||||||
module_dump = re.sub(r"( {4}def )(?!_)", r" async def ", module_dump) | ||||||||||||||
|
||||||||||||||
# Modify function calls. | ||||||||||||||
module_dump = re.sub(r"self\.client\.(.+)\(", r"await self.client.\1(", module_dump) | ||||||||||||||
module_dump = re.sub(r"= self\.(.+)\(", r"= await self.\1(", module_dump) | ||||||||||||||
module_dump = re.sub(r"send_request\(", r"await send_request(", module_dump) | ||||||||||||||
|
||||||||||||||
Comment on lines
+110
to
113
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Greedy The current patterns can unexpectedly swallow dots or spaces until the next “(”. -module_dump = re.sub(r"self\.client\.(.+)\(", r"await self.client.\1(", module_dump)
-module_dump = re.sub(r"= self\.(.+)\(", r"= await self.\1(", module_dump)
+module_dump = re.sub(r"self\.client\.([A-Za-z_][A-Za-z0-9_]*)\(", r"await self.client.\1(", module_dump)
+module_dump = re.sub(r"= (\s*)self\.([A-Za-z_][A-Za-z0-9_]*)\(", r"= \1await self.\2(", module_dump) 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||
# Modify property accesses. | ||||||||||||||
module_dump = module_dump.replace("self.api.version", "await self.api.version") | ||||||||||||||
|
||||||||||||||
module_processed.append(module_path) | ||||||||||||||
target_path = Path(str(module_path).replace(str(source), str(target))) | ||||||||||||||
with Path.open(target_path, "w") as fp: | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Function-definition regex misses indents ≠ 4 & may hit code snippets
" def foo"
string in a doc-string would also be changed.📝 Committable suggestion
🤖 Prompt for AI Agents