-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
49 additions
and
6 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
""" | ||
Fix to stubgen | ||
stubgen replaces NewType to Incomplete. | ||
We discover files with NewType and | ||
replace them in stubgen generated files back to NewType | ||
""" | ||
from pathlib import Path | ||
|
||
pathlist = Path(".").rglob('*.pyi') | ||
for path in pathlist: | ||
path_in_str = str(path) | ||
if ".venv" in path_in_str: | ||
continue | ||
|
||
with open(path_in_str, "r") as file: | ||
pyi_file = file.readlines() | ||
with open(path_in_str.replace("-stubs","").replace(".pyi", ".py"), "r") as file: | ||
py_file = file.readlines() | ||
|
||
has_new_types = False | ||
|
||
# replace in pyi files NewType back to original code line | ||
for py_line in py_file: | ||
if "NewType" in py_line: | ||
varname: str = py_line.split(" ")[0] | ||
has_new_types = True | ||
|
||
for pyi_i, pyi_line in enumerate(pyi_file): | ||
if f"{varname}: Incomplete\n" == pyi_line: | ||
pyi_file[pyi_i] = py_line | ||
|
||
if has_new_types: | ||
# replace from typing import back because | ||
# stubgen autoremoved some of it | ||
for py_line in py_file: | ||
if "from typing" in py_line: | ||
for pyi_i, pyi_line in enumerate(pyi_file): | ||
if f"from typing" in pyi_line: | ||
pyi_file[pyi_i] = py_line | ||
|
||
with open(path_in_str, "w") as file: | ||
file.writelines(pyi_file) |
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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
from typing import Any, Callable, Dict | ||
from typing import Any, Callable, Dict, NewType | ||
|
||
Serialazable = Any | ||
|
||
LogAttrs = Dict[str, Serialazable] | ||
LogAttrs = NewType("LogAttrs", Dict[str, Serialazable]) | ||
LogType = Callable[[LogAttrs], None] | ||
|
||
|
||
LibName = str | ||
LogLevel = int | ||
RootLogLevel = LogLevel | ||
LibName = NewType("LibName", str) | ||
LogLevel = NewType("LogLevel", int) | ||
RootLogLevel = NewType("RootLogLevel", int) |