Fix circular import of scapy in dhcp (#56040)

* Fix circular import of scapy in dhcp

* Tweak import, add comment

* Tweak import, add comment

* pylint
This commit is contained in:
J. Nick Koston 2021-09-10 10:04:54 +02:00 committed by GitHub
parent 970a7f9662
commit ff1b39cda6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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,
)