elastic / elastic/ecs-logging-python

StructlogProcessor fails typechecking

オープン
#146 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
agent-python community triage
主要言語
Python
スター
74
フォーク
33
平均マージ
9時間 3分
マージ済み PR(30日)
1

説明

When typechecking the following code:

```python
from structlog.typing import Processor

shared_processors: tuple[Processor, ...] = (
structlog.contextvars.merge_contextvars,
structlog.processors.add_log_level,
structlog.processors.StackInfoRenderer(),
structlog.dev.set_exc_info,
structlog.processors.TimeStamper(fmt="iso", utc=True),
)

processors: list[Processor]
if sys.stderr.isatty():
processors = [
*shared_processors,
structlog.dev.ConsoleRenderer(),
]
else:
processors = [
*shared_processors,
structlog.processors.dict_tracebacks,
ecs_logging.StructlogFormatter(),
]

structlog.configure(
processors=processors,
logger_factory=structlog.PrintLoggerFactory(),
cache_logger_on_first_use=True,
)
```

mypy raises the following:

```
error: List item 2 has incompatible type "StructlogFormatter"; expected
"Callable[[Any, str, MutableMapping[str, Any]], Union[Mapping[str, Any], str, bytes, bytearray, tuple[Any, ...]]]" [list-item]
ecs_logging.StructlogFormatter(),
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
note: "StructlogFormatter.__call__" has type "Callable[[Arg(Any, '_'), Arg(str, 'name'), Arg(dict[str, Any], 'event_dict')], str]"
```

`StructlogFormatter` is annotated as accepting a `dict[str, Any]`, but it needs to accept any `MutableMapping[str, Any]`. The code already conforms to this, so addressing this issue wil hopefully only involve updating the type annotation.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。