Last active
February 3, 2023 10:27
-
-
Save abersheeran/abfe6fa1d731affc5ec050408b7c5d4d to your computer and use it in GitHub Desktop.
Ensure that all Python modules in the specified directory are turned on pep563
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 | |
def ensure_pep563(dirpath: Path) -> None: | |
self_path = Path(__file__).absolute() | |
future_import = "from __future__ import annotations" | |
for pypath in dirpath.glob("**/*.py"): | |
if pypath.absolute() == self_path: | |
continue | |
if future_import not in pypath.read_text(): | |
pypath.write_text(f"{future_import}\n\n" + pypath.read_text()) | |
if __name__ == "__main__": | |
import sys | |
ensure_pep563(Path(sys.argv[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment