StructlogProcessor fails typechecking
评估
- 难度
- 1/5
- 预计耗时
- 1 小时以内
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 技术栈
- python
调研方向
从 StructlogFormatter.call 开始,检查 event_dict 的类型注解。使用提供的 mypy 示例重现该问题,更新注解使其接受所需的可变 mapping 类型,并确认 mypy 不再报告 list-item 错误。
由索引模型根据 Issue 内容生成。
描述
When typechecking the following code:
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.
- 主要语言
- Python
- 星标
- 74
- 派生
- 34
- 平均合并
- 1 天 2 分钟
- 30 天内合并 PR
- 1
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
elastic/ecs-logging-python 的其他 Issue
-
agent-python community triage
难度 2/5 1-3 小时 新手友好度 64/100
elastic/ecs-logging-python#170 ·
-
Exception Group Traceback not fully visible using StdlibFormatter可能已有人在做 @Shubham-Padkonde 于 19 天前认领。 未关闭agent-python community triage
难度 4/5 3-5 天 新手友好度 35/100
elastic/ecs-logging-python#185 · 6 条评论 ·
-
agent-python community enhancement
难度 4/5 3-5 天 新手友好度 35/100
elastic/ecs-logging-python#73 · 5 条评论 ·
-
agent-python community triage
难度 2/5 1-3 小时 新手友好度 50/100
elastic/ecs-logging-python#72 · 1 个 reaction ·
-
agent-python
难度 5/5 一周以上 新手友好度 25/100
elastic/ecs-logging-python#58 · 3 条评论 · 1 个 reaction ·
查看 elastic/ecs-logging-python 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
topoteretes/cognee#5647 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
Sendspin/sendspin-python-cli#291 ·
维护者通常 6 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
awslabs/visual-asset-management-system#414 ·
维护者通常 1 天内回复
-
bug v1 v2
难度 2/5 1-3 小时 新手友好度 75/100
modelcontextprotocol/python-sdk#3670 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
aicell-lab/bioengine#232 ·
维护者通常 1 天内回复