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: IPv4Interface Object has no attributte prefixlen
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Eddgar Rojas, andrei.avk, eudoxos, kj, pmoody
Priority: normal Keywords:

Created on 2019-03-21 19:45 by Eddgar Rojas, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg338566 - (view) Author: Eddgar Rojas (Eddgar Rojas) Date: 2019-03-21 19:45
The python the Class IPv4Interface  on the ipaddress module when I try to use the .prefixlen attribute it says that do not exist but is i have access by using ._prefixlen 

if i have on the IPv4Interface class the .netmask attribute and the .nethost attribute Why not the .prefixlen attribute?, 

I reported like a bug as i think that attribute should appear on the IPv4Interface Class

Below test I did 

>>> import ipaddress as ip
>>> addr = ip.ip_interface('192.168.1.1/24')
>>> addr.prefixlen
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'IPv4Interface' object has no attribute 'prefixlen'
>>> addr.netmask
IPv4Address('255.255.255.0')

>>> addr._prefixlen
24
msg396521 - (view) Author: Václav Šmilauer (eudoxos) * Date: 2021-06-25 08:21
This one works: addr.network.prefixlen.  It took me a while to find out; I find the documentation somewhat confusing in this point.
msg407699 - (view) Author: Andrei Kulakov (andrei.avk) * (Python triager) Date: 2021-12-05 04:55
The docs for current bugfix releases (3.9+) have clear links from the Interface class attribute `network` to the Network class which lists the `prefixlen` attribute. I don't think it can be made clearer - there's two ways to find it - either searching for `prefixlen` and working backwards from network to interface, or following the link from Interface.network.
msg407820 - (view) Author: Ken Jin (kj) * (Python committer) Date: 2021-12-06 14:52
The link to what Andrei is referring to:
https://docs.python.org/3/library/ipaddress.html#ipaddress.IPv4Network.prefixlen
History
Date User Action Args
2022-04-11 14:59:12adminsetgithub: 80573
2021-12-06 14:52:27kjsetmessages: + msg407820
2021-12-05 04:55:28andrei.avksetstatus: open -> closed

nosy: + kj, andrei.avk
messages: + msg407699

resolution: not a bug
stage: resolved
2021-06-25 08:21:30eudoxossetnosy: + eudoxos
messages: + msg396521
2019-03-21 19:53:14SilentGhostsetnosy: + pmoody
2019-03-21 19:45:12Eddgar Rojascreate