This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Documentation of ipaddress behavior for prefix length with leading zeros.
Type: enhancement Stage:
Components: Documentation Versions: Python 3.11, Python 3.10, Python 3.9, Python 3.8, Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, lay20114
Priority: normal Keywords:

Created on 2022-02-03 02:46 by lay20114, last changed 2022-04-11 14:59 by admin.

Messages (1)
msg412412 - (view) Author: Kenta Tsuna (lay20114) Date: 2022-02-03 02:46
ipaddress library tolerate the prefix length with leading zeros.
$ ./python.exe 
Python 3.11.0a4+ (heads/main:8fb3649450, Jan 31 2022, 16:39:46) [Clang 13.0.0 (clang-1300.0.29.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ipaddress
>>> ipaddress.ip_interface('192.0.2.0/0000000024')
IPv4Interface('192.0.2.0/24')
>>> ipaddress.ip_interface('2001:db8::/0000000032')
IPv6Interface('2001:db8::/32')

The explanation of this behavior exists in follow tests.
https://github.com/python/cpython/blob/51a95be1d035a717ab29e98056b8831a98e61125/Lib/test/test_ipaddress.py#L747-L748
https://github.com/python/cpython/blob/51a95be1d035a717ab29e98056b8831a98e61125/Lib/test/test_ipaddress.py#L755-L756
https://github.com/python/cpython/blob/51a95be1d035a717ab29e98056b8831a98e61125/Lib/test/test_ipaddress.py#L592-L593

But, it seems that the explanation does not exists in the document.
https://docs.python.org/3.11/library/ipaddress.html
https://docs.python.org/3.10/library/ipaddress.html
https://docs.python.org/3.9/library/ipaddress.html
https://docs.python.org/3.8/library/ipaddress.html
https://docs.python.org/3.7/library/ipaddress.html
History
Date User Action Args
2022-04-11 14:59:55adminsetgithub: 90778
2022-02-03 02:46:49lay20114create