StructlogProcessor fails typechecking
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- python
- Domain
- observability-sre
Research direction
Start at StructlogFormatter.call and inspect its event_dict type annotation. Reproduce the issue with the provided mypy example, update the annotation so it accepts the required mutable mapping type, and confirm that mypy no longer reports the list-item error.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Python
- Stars
- 74
- Forks
- 33
- Avg merge
- 9h 3m
- Merged PRs (30d)
- 1
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from elastic/ecs-logging-python
-
agent-python community triage
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
elastic/ecs-logging-python#170 ·
-
agent-python community triage
Difficulty 4/5 3-5 days Newbie friendliness 35/100
elastic/ecs-logging-python#185 · 6 comments ·
-
agent-python community enhancement
Difficulty 4/5 3-5 days Newbie friendliness 35/100
elastic/ecs-logging-python#73 · 5 comments ·
-
agent-python community triage
Difficulty 2/5 1-3 hours Newbie friendliness 50/100
elastic/ecs-logging-python#72 · 1 reaction ·
-
agent-python
Difficulty 5/5 Over a week Newbie friendliness 25/100
elastic/ecs-logging-python#58 · 3 comments · 1 reaction ·
All issues in elastic/ecs-logging-python
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
use-agent-os/agent-os#3314 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
BasedHardware/omi#15662 · 1 comment ·
-
documentation help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
AiursoftWeb/AnduinOS-2#19 ·