From cdfdc7c4f5603c00f5652d5044b15f4853d32285 Mon Sep 17 00:00:00 2001 From: Kotesh Kumar Yelamati Date: Fri, 3 Jul 2026 16:24:56 -0400 Subject: [PATCH] fix: raise clear TypeError for non-int in long2ip() In Python 3, the comparison `MAX_IP < None` raises: TypeError: '<' not supported between instances of 'int' and 'NoneType' This differs from the doctest which expects the Python 2 error message: TypeError: unsupported operand type(s) for >>: 'NoneType' and 'int' Fix: add an explicit isinstance check before the comparison so that non-integer inputs raise a clear, consistent TypeError. --- iptools/ipv4.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iptools/ipv4.py b/iptools/ipv4.py index 3243482..9a31360 100644 --- a/iptools/ipv4.py +++ b/iptools/ipv4.py @@ -445,7 +445,7 @@ def long2ip(l): :returns: Dotted-quad ip address (eg. '127.0.0.1'). :raises: TypeError """ - if MAX_IP < l or l < MIN_IP: + if not isinstance(l, int) or isinstance(l, bool) or MAX_IP < l or l < MIN_IP: raise TypeError( "expected int between %d and %d inclusive" % (MIN_IP, MAX_IP)) return '%d.%d.%d.%d' % (