Skip to content

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
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.

@serhiy-storchaka
Copy link
Member

I think that instead of overloading and slowing down main constructors, we should add more specific alternative constructors -- from bytes (accepts also anything that implements the buffer protocol), from integer, from string.

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.

4 participants