Skip to content

urllib.parse.urlsplit rejects documented bytearray inputs as unhashable #158766

Description

@augusto-rehfeldt

Bug report

Bug description:

Documented behaviour: The urllib.parse documentation, section 'Parsing ASCII Encoded Bytes', states: "Accordingly, the URL parsing functions in this module all operate on bytes and bytearray objects in addition to str objects."

Expected: SplitResultBytes(scheme=b'', netloc=b'', path=b'', query=b'', fragment=b'')

Actual: TypeError: unhashable type: 'bytearray'

import urllib.parse as p

s = ""
x = bytearray(s, "ascii")
expected = p.SplitResultBytes(b"", b"", b"", b"", b"")
try:
    valid = isinstance(x, bytearray) and s.isascii() and p.urlsplit(s).encode("ascii") == expected
except Exception as e:
    valid = False

if not valid:
    print("REFUTATION REJECTED:", "input or reference validation failed")
else:
    try:
        actual = p.urlsplit(x)
        broken = not isinstance(actual, p.SplitResultBytes) or actual != expected
    except Exception as e:
        actual = ("exception", type(e).__name__, str(e))
        broken = True
    if broken:
        print("REFUTATION CONFIRMED:", repr(x), "actual:", actual, "expected:", expected)
    else:
        print("REFUTATION REJECTED:", "actual matches the documented expectation")

Output on Python 3.14.6 (Windows-11-10.0.26220-SP0), standard library urllib.parse:

REFUTATION CONFIRMED: bytearray(b'') actual: ('exception', 'TypeError', "unhashable type: 'bytearray'") expected: SplitResultBytes(scheme=b'', netloc=b'', path=b'', query=b'', fragment=b'')

This report was found and written by an automated property-testing tool I run (bugforge). The reproducer above was executed and its output is pasted unedited; no person reviewed the report before it was filed. The search script is in https://github.com/augusto-rehfeldt/bugforge-results/tree/main/urllib.parse-20261003-015128-c1

CPython versions tested on:

3.14

Operating systems tested on:

Windows

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions