Issues in ipaddress.collapse_addresses()
Open
Nobody has claimed this yet.
3.13
3.14
3.15
3.16
stdlib
type-bug
type-feature
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
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
- gh-149723
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the ipaddress.collapse_addresses() entry point and the existing dedicated tests mentioned in the report. Review linked PR gh-149723 before changing behavior. Done means documenting supported IP addresses, deciding how IP interfaces are handled, raising TypeError consistently for invalid inputs, and adding corner-case tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100