Skip to content

Commit

Permalink
refactor: added some types and updatedd some docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Rishabh672003 committed Jun 30, 2024
1 parent 9c94ff3 commit 79c9e09
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/pyfix_imports/commandline/cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pathlib import Path

import click

from pyfix_imports.file import write_to_file
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/pyfix_imports/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

4 changes: 2 additions & 2 deletions src/pyfix_imports/fix_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
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:
filename: path of file to be fixed.
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)
Expand Down

0 comments on commit 79c9e09

Please sign in to comment.