From f55ebd8809feae54b1f88bf8c8ac6e546d027141 Mon Sep 17 00:00:00 2001 From: Terje Kvernes Date: Mon, 11 Dec 2023 12:41:23 +0100 Subject: [PATCH] Support a proper IP_Version type... - Literal doesn't exist for <3.7, so there we use _int_. How quaint. --- mreg_cli/types.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/mreg_cli/types.py b/mreg_cli/types.py index ac8762d3..ba35883b 100644 --- a/mreg_cli/types.py +++ b/mreg_cli/types.py @@ -1,12 +1,19 @@ """Typing definitions for mreg_cli.""" import ipaddress +import sys from typing import TYPE_CHECKING, Union +# Horrible heck to support Literal on Python 3.6 +if sys.version_info >= (3, 7): + from typing_extensions import Literal + + IP_Version = Literal[4, 6] +else: + from typing import int + + IP_Version = int + IP_network = Union[ipaddress.IPv4Network, ipaddress.IPv6Network] -# IP_Version = Literal[4, 6] -# IP_Version can be either 4 or 6, but Literal is not supported in older versions of Python. -# We could use typing_extensions.Literal, but that would require an extra dependency. -IP_Version = int if TYPE_CHECKING: