Skip to content

gh-78646: Add bytearray support to ipaddress #135811

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
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

matan1008
Copy link
Contributor

@matan1008 matan1008 commented Jun 22, 2025

@picnixz
Copy link
Member

picnixz commented Jun 22, 2025

The original issue did not reach a consensus IMO and there was a suggestion:

Maybe add a special purposed named constructor IPv4Address.from_bytes() that will accept any objects supporting the buffer protocol?

cc @serhiy-storchaka

@picnixz picnixz added the pending The issue will be closed if no feedback is provided label Jun 22, 2025
@@ -1292,7 +1292,7 @@ def __init__(self, address):
return

# Constructing from a packed address
if isinstance(address, bytes):
if isinstance(address, bytes) or isinstance(address, bytearray):
self._check_packed_address(address, 4)
self._ip = int.from_bytes(address) # big endian
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as a note, the int.from_bytes here will still memcpy to go from bytearray -> bytes internally (gh-132108). So this is just moving the need to copy at the moment, not eliminating entirely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review pending The issue will be closed if no feedback is provided
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants