Skip to content

fix: raise clear TypeError for non-int in long2ip()#33

Open
koteshyelamati wants to merge 1 commit into
bd808:masterfrom
koteshyelamati:patch-1
Open

fix: raise clear TypeError for non-int in long2ip()#33
koteshyelamati wants to merge 1 commit into
bd808:masterfrom
koteshyelamati:patch-1

Conversation

@koteshyelamati

Copy link
Copy Markdown

Bug Fix

In Python 3, long2ip(None) raises:

TypeError: '<' not supported between instances of 'int' and 'NoneType'

This comes from the comparison MAX_IP < l failing when l is None.
The doctest (which was written for Python 2) expects:

TypeError: unsupported operand type(s) for >>: 'NoneType' and 'int'

In Python 2, None < int was valid (always False), so execution reached the >> bit-shift operator. In Python 3, the comparison itself raises TypeError.

Fix

Added an explicit isinstance check before the comparison so that None and other non-integer inputs raise a consistent, clear TypeError("expected int between 0 and 4294967295 inclusive") — the same message already raised for out-of-range integers.

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.
@bd808

bd808 commented Jul 3, 2026

Copy link
Copy Markdown
Owner

I’m not sure I see the point of replacing a type error with a type error that has a different description after extra steps. What is your use case for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants