Skip to content

cpython difference in bind(), connect() arguments #8957

Closed
@jepler

Description

@jepler

CircuitPython version

9.0.0-beta

Code/REPL

>>> s = pool.socket() # or socket.socket
>>> b = bytearray(b'0.0.0.0')
>>> s.connect((b, 443))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't convert 'bytearray' object to str implicitly

Behavior

In standard Python, the bytearray is accepted (and the connection fails, because there's no listener):

Python 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] on linux
>>> b = bytearray(b'0.0.0.0')
>>> s.connect((b, 443))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ConnectionRefusedError: [Errno 111] Connection refused

Similar for bind():

# circuitpython
>>> s.bind((bytearray(), 1234))
TypeError: can't convert 'bytearray' object to str implicitly

vs

# cpython 3.11
>>> s.bind((bytearray(), 1234))
>>> 

Description

No response

Additional information

I ran into this while working on #8954. In that PR I was converting the bind/connect argument to a bytearray (because this let me avoid an allocation) but it didn't work.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions