Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Lint type annotations using mypy #311

Merged
merged 2 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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