-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also fixed most stubgen warnings by delaying method binding to after class creation.
- Loading branch information
Showing
23 changed files
with
909 additions
and
690 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env python3 | ||
|
||
""" | ||
Fixes errors in .pyi files generated by stubgen. | ||
""" | ||
|
||
import re | ||
import os | ||
import sys | ||
|
||
|
||
def main(): | ||
# sys.argv[1] should be a directory in which to search for .pyi files | ||
filenames = [ | ||
os.path.join(dp, f) | ||
for dp, dn, fn in os.walk(sys.argv[1]) | ||
for f in fn | ||
if f.endswith(".pyi") | ||
] | ||
for filename in filenames: | ||
with open(filename) as f: | ||
content = f.read() | ||
|
||
# Fix errors | ||
content = content.replace( | ||
"<ExpressionType.NONE: 0>", "ExpressionType.NONE" | ||
).replace("<SolverExitCondition.SUCCESS: 0>", "SolverExitCondition.SUCCESS") | ||
|
||
# Convert parameter names from camel case to snake case | ||
new_content = "" | ||
extract_location = 0 | ||
for match in re.finditer(r"(?<=Parameter ``)(.*?)(?=``:)", content): | ||
new_content += content[extract_location : match.start()] | ||
new_content += re.sub(r"(?<!^)(?=[A-Z])", "_", match.group()).lower() | ||
extract_location = match.end() | ||
content = new_content + content[extract_location:] | ||
|
||
with open(filename, mode="w") as f: | ||
f.write(content) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.