Skip to content

Commit

Permalink
Improvements to support type-hinting
Browse files Browse the repository at this point in the history
When attempting to use the output functions in plugins, mypy was warning
about calling untyped functions. The changes to output.py should resolve
this.

It's also necessary to import the ImportGraph protocol when creating a
plugin, so it makes sense that this should be exported at the top level
too. This avoids needing to reach deep into the package.
  • Loading branch information
mwg-rea authored and seddonym committed Dec 27, 2022
1 parent c11c22c commit a993014
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/importlinter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
from .application import output # noqa
from .domain import fields # noqa
from .domain.contract import Contract, ContractCheck # noqa
from importlinter.domain.ports.graph import ImportGraph # noqa


__all__ = ["output", "fields", "Contract", "ContractCheck", "ImportGraph"]
10 changes: 5 additions & 5 deletions src/importlinter/application/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ def print(
"""
self.printer.print(text, bold, color, newline)

def indent_cursor(self):
def indent_cursor(self) -> None:
"""
Indents the cursor ready to print a line.
"""
self.printer.print(" " * INDENT_SIZE, newline=False)

def new_line(self):
def new_line(self) -> None:
"""
Print a blank line.
"""
Expand Down Expand Up @@ -84,19 +84,19 @@ def print_heading(self, text: str, level: int, style: Optional[str] = None) -> N
self.printer.print(heading_line, bold=is_bold, color=color)
self.printer.print()

def print_success(self, text, bold=True):
def print_success(self, text: str, bold: bool = True) -> None:
"""
Prints a line to the console, formatted as a success.
"""
self.printer.print(text, color=COLORS[SUCCESS], bold=bold)

def print_error(self, text, bold=True):
def print_error(self, text: str, bold: bool = True) -> None:
"""
Prints a line to the console, formatted as an error.
"""
self.printer.print(text, color=COLORS[ERROR], bold=bold)

def print_warning(self, text):
def print_warning(self, text: str) -> None:
"""
Prints a line to the console, formatted as a warning.
"""
Expand Down

0 comments on commit a993014

Please sign in to comment.