Skip to content

Commit

Permalink
feat: Lint type annotations using mypy (#311)
Browse files Browse the repository at this point in the history
* fix: Type annotation issues detected by mypy

* feat: Lint type annotations using mypy
  • Loading branch information
l0b0 authored Oct 14, 2024
1 parent 403284c commit b50b535
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 9 deletions.
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ repos:
stages: [commit]
types: [python]

- id: mypy
name: mypy
entry: mypy
args: [--no-incremental]
language: system
stages: [commit]
types: [python]
require_serial: true

- id: pylint
name: pylint
entry: pylint
Expand Down
7 changes: 4 additions & 3 deletions linz_logger/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from enum import Enum
from functools import partial
from platform import node
from typing import Any, MutableMapping

import structlog
from structlog.contextvars import bind_contextvars, clear_contextvars, merge_contextvars, unbind_contextvars
Expand All @@ -27,7 +28,7 @@ class LogLevel(Enum):


current_level = LogLevel.debug
structlog.PrintLogger.trace = structlog.PrintLogger.msg
structlog.PrintLogger.trace = structlog.PrintLogger.msg # type: ignore[attr-defined]
pid = os.getpid()
hostname = node()
ulid = str(ULID())
Expand Down Expand Up @@ -61,7 +62,7 @@ def remove_contextvars(keys):
unbind_contextvars(*keys)


def level_filter(_, __, event_dict: dict):
def level_filter(_, __, event_dict: MutableMapping[str, Any]):
"""
Silently drop logs lower than the set level.
"""
Expand All @@ -73,7 +74,7 @@ def level_filter(_, __, event_dict: dict):
# This is a standard format for the function so it needs all three arguments
# Even thought we do not use them
# pylint: disable=unused-argument
def add_default_keys(current_logger, method_name: str, event_dict: dict):
def add_default_keys(current_logger, method_name: str, event_dict: MutableMapping[str, Any]):
"""
Configure structlog to output the same format as pinojs
{
Expand Down
69 changes: 63 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ python-ulid = "^1.1.0"
[tool.poetry.group.dev.dependencies]
black = "^24.1.1"
isort = "^5.13.1"
mypy = "*"
pre-commit = "*"
pylint = "^3.0.2"
pytest = ">=7.4.4,<9.0.0"
Expand Down

0 comments on commit b50b535

Please sign in to comment.