Skip to content

Commit

Permalink
Add some more type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Nov 12, 2023
1 parent dc7e75b commit 180ce25
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 9 deletions.
22 changes: 20 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.4
rev: v0.1.5
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand All @@ -24,8 +24,26 @@ repos:
- id: trailing-whitespace
exclude: tests/data/expected_output.py

# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: v1.7.0
# hooks:
# - id: mypy
# args: [--pretty, --show-error-codes]
# additional_dependencies:
# [
# freezegun,
# platformdirs,
# prettytable,
# pytablewriter,
# pytest,
# respx,
# termcolor,
# types-python-dateutil,
# types-python-slugify,
# ]

- repo: https://github.com/tox-dev/pyproject-fmt
rev: 1.4.1
rev: 1.5.1
hooks:
- id: pyproject-fmt
additional_dependencies: [tox]
Expand Down
2 changes: 1 addition & 1 deletion scripts/run_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import subprocess


def run(command: str, with_console: bool = True, line_limit: int = None) -> None:
def run(command: str, with_console: bool = True, line_limit: int | None = None) -> None:
output = subprocess.run(command.split(), capture_output=True, text=True)
print()
if with_console:
Expand Down
9 changes: 6 additions & 3 deletions src/norwegianblue/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ def _apply_colour(text: str, colour: str, *, is_html: bool = False) -> str:


def _tabulate(
data: list[dict], format_: str = "markdown", color: str = "yes", title: str = None
data: list[dict],
format_: str = "markdown",
color: str = "yes",
title: str | None = None,
) -> str:
"""Return data in specified format"""

Expand Down Expand Up @@ -212,7 +215,7 @@ def _prettytable(
data: list[dict],
format_: str,
color: str = "yes",
title: str = None,
title: str | None = None,
) -> str:
from prettytable import MARKDOWN, SINGLE_BORDER, PrettyTable

Expand Down Expand Up @@ -240,7 +243,7 @@ def _prettytable(


def _pytablewriter(
headers: list[str], data: list[dict], format_: str, title: str = None
headers: list[str], data: list[dict], format_: str, title: str | None = None
) -> str:
from pytablewriter import (
CsvTableWriter,
Expand Down
2 changes: 1 addition & 1 deletion src/norwegianblue/_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def filename(url: str) -> Path:
return CACHE_DIR / f"{today}-{slug}.json"


def load(cache_file):
def load(cache_file: Path):
"""Load data from cache_file"""
if not cache_file.exists():
return {}
Expand Down
2 changes: 1 addition & 1 deletion src/norwegianblue/_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
d[chr(i + c)] = chr((i + 47) % 94 + c)


def text(s):
def text(s: str) -> str:
return "".join([d.get(c, c) for c in s])


Expand Down
3 changes: 2 additions & 1 deletion tests/test_norwegianblue.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import json
import os
from pathlib import Path
from typing import Any
from unittest import mock

import pytest
Expand Down Expand Up @@ -42,7 +43,7 @@
EXPECTED_MD_WITH_TITLE = "## ubuntu\n" + EXPECTED_MD


def stub__cache_filename(*args):
def stub__cache_filename(*args: Any) -> Path:
return Path("/this/does/not/exist")


Expand Down

0 comments on commit 180ce25

Please sign in to comment.