From 12c9d8d8f83cc0cf25328cf345ba2ad84396394b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 6 Oct 2020 06:50:17 +0530 Subject: [PATCH] Delay load the ipaddress module --- kittens/hints/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kittens/hints/main.py b/kittens/hints/main.py index 4eaa29da1..d25c95aa6 100644 --- a/kittens/hints/main.py +++ b/kittens/hints/main.py @@ -2,7 +2,6 @@ # vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal -import ipaddress import os import re import string @@ -288,12 +287,13 @@ def quotes(text: str, s: int, e: int) -> Tuple[int, int]: @postprocessor def ip(text: str, s: int, e: int) -> Tuple[int, int]: + from ipaddress import ip_address # Check validity of IPs (or raise InvalidMatch) ip = text[s:e] try: - ipaddress.ip_address(ip) - except ValueError: + ip_address(ip) + except Exception: raise InvalidMatch("Invalid IP") return s, e