From ff1b39cda6e84c2e3046f7d436b479994f24ce7a Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 10 Sep 2021 10:04:54 +0200 Subject: [PATCH] Fix circular import of scapy in dhcp (#56040) * Fix circular import of scapy in dhcp * Tweak import, add comment * Tweak import, add comment * pylint --- homeassistant/components/dhcp/__init__.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/homeassistant/components/dhcp/__init__.py b/homeassistant/components/dhcp/__init__.py index cc89c9b785d..e6debfea2eb 100644 --- a/homeassistant/components/dhcp/__init__.py +++ b/homeassistant/components/dhcp/__init__.py @@ -279,6 +279,17 @@ class DHCPWatcher(WatcherBase): """Start watching for dhcp packets.""" # Local import because importing from scapy has side effects such as opening # sockets + from scapy import ( # pylint: disable=import-outside-toplevel,unused-import # noqa: F401 + arch, + ) + + # + # Importing scapy.sendrecv will cause a scapy resync which will + # import scapy.arch.read_routes which will import scapy.sendrecv + # + # We avoid this circular import by importing arch above to ensure + # the module is loaded and avoid the problem + # from scapy.sendrecv import ( # pylint: disable=import-outside-toplevel AsyncSniffer, )