Skip to content
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

Error in ipaddress.address_exclude function #70644

Closed
out mannequin opened this issue Feb 29, 2016 · 5 comments
Closed

Error in ipaddress.address_exclude function #70644

out mannequin opened this issue Feb 29, 2016 · 5 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@out
Copy link
Mannequin

out mannequin commented Feb 29, 2016

BPO 26457
Nosy @ncoghlan, @serhiy-storchaka, @zhangyangyu
Files
  • address_exclude.patch: ipaddress._BaseNetwork.subnets include broadcast network
  • 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 = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2016-03-01.08:26:58.359>
    created_at = <Date 2016-02-29.06:29:44.490>
    labels = ['type-bug', 'library']
    title = 'Error in ipaddress.address_exclude function'
    updated_at = <Date 2016-03-01.08:26:58.359>
    user = 'https://bugs.python.org/out'

    bugs.python.org fields:

    activity = <Date 2016-03-01.08:26:58.359>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2016-03-01.08:26:58.359>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2016-02-29.06:29:44.490>
    creator = 'out'
    dependencies = []
    files = ['42054']
    hgrepos = []
    issue_num = 26457
    keywords = ['patch']
    message_count = 5.0
    messages = ['260994', '261037', '261041', '261042', '261043']
    nosy_count = 6.0
    nosy_names = ['ncoghlan', 'pmoody', 'python-dev', 'serhiy.storchaka', 'xiang.zhang', 'out']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue26457'
    versions = ['Python 3.5', 'Python 3.6']

    @out
    Copy link
    Mannequin Author

    out mannequin commented Feb 29, 2016

    when i read in document 3.5.1,run the example in ipaddress.address_exclude function

    >> n1 = ip_network('192.0.2.0/28')
    >> n2 = ip_network('192.0.2.1/32')
    >> list(n1.address_exclude(n2))

    I got:

    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:\Python 3.5\lib\ipaddress.py", line 794, in address_exclude
        s1, s2 = s1.subnets()
    ValueError: not enough values to unpack (expected 2, got 1)

    @out out mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Feb 29, 2016
    @zhangyangyu
    Copy link
    Member

    In old ipaddr.py, IPv4Network('192.0.2.0/31').subnet() returns [IPv4Network('192.0.2.0/32'), IPv4Network('192.0.2.1/32')], but ipaddress returns only [IPv4Network('192.0.2.0/32')].

    It seems simply change end to end+1 in https://hg.python.org/cpython/file/tip/Lib/ipaddress.py#l921 can solve the problem and pass the test. But maybe there are some side effects.

    @zhangyangyu
    Copy link
    Member

    I propose a patch simply add one to end so that the broadcast address network will appear in the result, which behaves the same as ipaddr.py. Corresponding tests are added. All tests are passed but I am afraid some logic may break.

    @serhiy-storchaka
    Copy link
    Member

    LGTM. I have wrote similar patch but with different tests.

    @serhiy-storchaka serhiy-storchaka self-assigned this Mar 1, 2016
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Mar 1, 2016

    New changeset 6d6c0a7b71f5 by Serhiy Storchaka in branch '3.5':
    Issue bpo-26457: Fixed the subnets() methods in IP network classes for the case
    https://hg.python.org/cpython/rev/6d6c0a7b71f5

    New changeset c092148a1b55 by Serhiy Storchaka in branch 'default':
    Issue bpo-26457: Fixed the subnets() methods in IP network classes for the case
    https://hg.python.org/cpython/rev/c092148a1b55

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants