Network = Union["ipaddress.IPv4Network", "ipaddress.IPv6Network"]
# These functions will be imported lazily
+imported = False
ip_address: Callable[[str], Address]
ip_interface: Callable[[str], Interface]
ip_network: Callable[[str], Network]
class _LazyIpaddress(Loader):
def __init__(self, oid: int, context: Optional[AdaptContext] = None):
super().__init__(oid, context)
- global ip_address, ip_interface, ip_network
- from ipaddress import ip_address, ip_interface, ip_network
+ global imported, ip_address, ip_interface, ip_network
+ if not imported:
+ from ipaddress import ip_address, ip_interface, ip_network
+
+ imported = True
@Loader.text(builtins["inet"].oid)
import uuid
# Importing the uuid module is slow, so import it only on request.
+imported = False
UUID: Callable[..., "uuid.UUID"]
def __init__(self, oid: int, context: Optional[AdaptContext] = None):
super().__init__(oid, context)
- global UUID
- from uuid import UUID
+ global imported, UUID
+ if not imported:
+ from uuid import UUID
+
+ imported = True
def load(self, data: bytes) -> "uuid.UUID":
return UUID(data.decode("utf8"))