Created
December 8, 2016 08:30
-
-
Save k-saka/4451eeae35b0cbd99eb60ab9041a0a49 to your computer and use it in GitHub Desktop.
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
from pathlib import Path | |
from typing import Iterable, Iterator | |
import tempfile | |
import shutil | |
_basepath = Path("") | |
def glob_files() -> Iterator[Path]: | |
files = _basepath.rglob("*.py") | |
return files | |
def annotate_init(pyfile: Path) -> None: | |
with tempfile.NamedTemporaryFile("w") as tmp: | |
with pyfile.open("r") as f: | |
for line in f: | |
if "def __init__(" in line and line.endswith(":\n") and "-> None:" not in line: | |
print(line) | |
line = line.replace("):", ") -> None:") | |
print(line) | |
tmp.write(line) | |
tmp.flush() | |
shutil.copy2(tmp.name, str(pyfile)) | |
# print(tmp.name, str(pyfile)) | |
def annotate(files: Iterable[Path]): | |
for pyfile in files: | |
annotate_init(pyfile) | |
files = glob_files() | |
annotate(files) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment