From 79c9e096fbf0eb9800a1c78c48ed7553effce006 Mon Sep 17 00:00:00 2001 From: Rishabh <53911515+Rishabh672003@users.noreply.github.com> Date: Sun, 30 Jun 2024 10:50:52 +0530 Subject: [PATCH] refactor: added some types and updatedd some docs --- src/pyfix_imports/commandline/cli.py | 4 +++- src/pyfix_imports/file.py | 4 ++-- src/pyfix_imports/fix_code.py | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/pyfix_imports/commandline/cli.py b/src/pyfix_imports/commandline/cli.py index b4e18a9..59a9044 100644 --- a/src/pyfix_imports/commandline/cli.py +++ b/src/pyfix_imports/commandline/cli.py @@ -1,3 +1,5 @@ +from pathlib import Path + import click from pyfix_imports.file import write_to_file @@ -19,7 +21,7 @@ "filename", type=click.Path(exists=True, dir_okay=False, readable=True), ) -def cli(filename: str, fix: bool, config_file) -> str | None: +def cli(filename: str, fix: bool, config_file: Path | None) -> str | None: fixed_code = fix_code(filename, config_file) if not fix: diff --git a/src/pyfix_imports/file.py b/src/pyfix_imports/file.py index 69a392b..18230cb 100644 --- a/src/pyfix_imports/file.py +++ b/src/pyfix_imports/file.py @@ -10,10 +10,10 @@ def get_file_text(filename: str) -> str: return output.lstrip().rstrip() -def write_to_file(filename:str, text: str): + +def write_to_file(filename: str, text: str): try: with open(filename, "w") as file: file.write(text) except Exception: return None - diff --git a/src/pyfix_imports/fix_code.py b/src/pyfix_imports/fix_code.py index 9b8b3e3..fab2bf4 100644 --- a/src/pyfix_imports/fix_code.py +++ b/src/pyfix_imports/fix_code.py @@ -4,7 +4,7 @@ from pyfix_imports.pyflake import pyflake -def fix_code(filename: str, config_file = None) -> str: +def fix_code(filename: str, config_file=None) -> str: """Fix the python source code of a file. Args: @@ -12,7 +12,7 @@ def fix_code(filename: str, config_file = None) -> str: config_file(Optional): path of the config file Returns: - Fixed code retrieved from file. + Fixed code as a string original file is not touched. """ config(config_file) output = get_file_text(filename)