KernelFactsDict.live_patches reads as a required key at runtime #144

Open
opened 2026-12-01 12:13:20 +00:00 by christianmanivong · 0 comments
Owner

napalm_device_types/kernel_models.py declares live_patches: NotRequired[LivePatchesDict] under from __future__ import annotations. With string annotations, TypedDict does not see the NotRequired wrapper, so at runtime:

>>> from napalm_device_types.models import KernelFactsDict
>>> KernelFactsDict.__optional_keys__
frozenset()

mypy reads the source and is not affected, so type checking is right; runtime introspection (__optional_keys__, __required_keys__) is wrong. Found while adding HostFirewallDict.windows (NetOrk/netork#2894), where the same thing happened; host_firewall_models.py therefore has no from __future__ import annotations.

Fix: drop the future import from kernel_models.py (its annotations need no forward references), and a test on KernelFactsDict.__optional_keys__.

Priority: P4: no known consumer introspects the keys.

`napalm_device_types/kernel_models.py` declares `live_patches: NotRequired[LivePatchesDict]` under `from __future__ import annotations`. With string annotations, `TypedDict` does not see the `NotRequired` wrapper, so at runtime: ``` >>> from napalm_device_types.models import KernelFactsDict >>> KernelFactsDict.__optional_keys__ frozenset() ``` mypy reads the source and is not affected, so type checking is right; runtime introspection (`__optional_keys__`, `__required_keys__`) is wrong. Found while adding `HostFirewallDict.windows` (NetOrk/netork#2894), where the same thing happened; `host_firewall_models.py` therefore has no `from __future__ import annotations`. Fix: drop the future import from `kernel_models.py` (its annotations need no forward references), and a test on `KernelFactsDict.__optional_keys__`. **Priority:** P4: no known consumer introspects the keys.
christianmanivong added the
prio
P4
bug
labels 2026-12-01 12:13:20 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: NAPALM/napalm-device-types#144