Skip to content

address arg can be bytes for ip_* functions in ipaddress module #90804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
sobolevn opened this issue Feb 5, 2022 · 3 comments
Open

address arg can be bytes for ip_* functions in ipaddress module #90804

sobolevn opened this issue Feb 5, 2022 · 3 comments
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error

Comments

@sobolevn
Copy link
Member

sobolevn commented Feb 5, 2022

BPO 46646
Nosy @merwok, @sobolevn
PRs
  • bpo-46646: mention that bytes are accepted in ipaddress docs #31139
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2022-02-05.07:05:52.750>
    labels = ['3.11', 'type-bug', '3.9', '3.10', 'docs']
    title = '`address` arg can be `bytes` for `ip_*` functions in `ipaddress` module'
    updated_at = <Date 2022-02-12.12:17:20.741>
    user = 'https://github.com/sobolevn'

    bugs.python.org fields:

    activity = <Date 2022-02-12.12:17:20.741>
    actor = 'eric.araujo'
    assignee = 'docs@python'
    closed = False
    closed_date = None
    closer = None
    components = ['Documentation']
    creation = <Date 2022-02-05.07:05:52.750>
    creator = 'sobolevn'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46646
    keywords = ['patch']
    message_count = 2.0
    messages = ['412562', '413125']
    nosy_count = 4.0
    nosy_names = ['eric.araujo', 'pmoody', 'docs@python', 'sobolevn']
    pr_nums = ['31139']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue46646'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    @sobolevn
    Copy link
    Member Author

    sobolevn commented Feb 5, 2022

    Right now the docs say:

    ipaddress.ip_interface(address)
    Return an IPv4Interface or IPv6Interface object depending on the IP address passed as argument. **address is a string or integer** representing the IP address. Either IPv4 or IPv6 addresses may be supplied; integers less than 2**32 will be considered to be IPv4 by default. A ValueError is raised if address does not represent a valid IPv4 or IPv6 address.

    Note the address is a string or integer part.

    But, this is not true. Counter example:

    >>> import ipaddress
    >>> ipaddress.ip_interface(b'0000')
    IPv4Interface('48.48.48.48/32')
    >>> ipaddress.ip_interface(b'1111')
    IPv4Interface('49.49.49.49/32')
    

    So, packed version that accepts bytes, should be also mentioned.

    For ip_address types are not mentioned:

    ipaddress.ip_address(address)
    Return an IPv4Address or IPv6Address object depending on the IP address passed as argument. Either IPv4 or IPv6 addresses may be supplied; integers less than 2**32 will be considered to be IPv4 by default. A ValueError is raised if address does not represent a valid IPv4 or IPv6 address.

    I will send a PR with proposed changes.

    @sobolevn sobolevn added 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes labels Feb 5, 2022
    @sobolevn sobolevn added docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes labels Feb 5, 2022
    @sobolevn sobolevn added docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error labels Feb 5, 2022
    @merwok
    Copy link
    Member

    merwok commented Feb 12, 2022

    Can you dig more to find if the problem is in the code or in the doc?
    The PEP to add ipaddress should specify this.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @AlexWaygood
    Copy link
    Member

    Can you dig more to find if the problem is in the code or in the doc? The PEP to add ipaddress should specify this.

    The PEP does not specify this, as far as I can tell: https://peps.python.org/pep-3144/. Nor do the docs attached to the reference implementation that the PEP links to.

    The linked PR proposes documenting that bytes are supported for ipaddress.ip_address, ipaddress.ip_network and ipaddress.ip_interface. Of these three functions, I can only find a test for bytes for ipaddress.ip_interface:

    ipaddress.ip_interface(b'\x01\x02\x03\x04')._ip)
    . The other functions probably shouldn't be documented as supporting bytes if it's completely untested.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes 3.10 only security fixes 3.11 only security fixes docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants