Skip to content

Issues in ipaddress.collapse_addresses() #149722

@serhiy-storchaka

Description

@serhiy-storchaka

Bug report

The following issues was discovered during reviewing #141842:

  • ipaddress.collapse_addresses() supports not only IP networks, but also IP addresses and a mix of them. There are dedicated tests, but this is not documented.
  • ipaddress.collapse_addresses() contains code for supporting also IP interfaces, but it always was broken (it would work if interfaces were not subclasses of addresses). The test for mix of IP addresses and IP interfaces is mislabeled (it says a mix of addresses and networks) and partially commented out (it only tests addresses now, which is mostly a duplicate of other test).
  • While TypeError is raised immediately for IP addresses of different versions and IP networks of different versions, it is delayed until the start of iteration for a mix of IP addresses and IP networks with addresses and networks having different versions.
  • For objects other that IP objects you can get AttributeError instead of TypeError.

My plan for a fix:

  • Document support of IP addresses.
  • Explicitly forbid IP interfaces.
  • Always raise TypeError for invalid types (the code is simpler this way).
  • Add tests for corner cases.

For new version only:

  • Implement support of IP interfaces and document it as a new feature.
  • Either raise TypeError immediately for IP objects of different versions, or remove redundant explicit checks, they will be raised implicitly in comparisons.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixes3.15pre-release feature fixes, bugs and security fixes3.16new features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errortype-featureA feature request or enhancement

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions