bencode.py icon indicating copy to clipboard operation
bencode.py copied to clipboard

Encoder does not support base type - None

Open CrazyLionHeart opened this issue 5 years ago • 2 comments

Version: bencode.py==2.1.0

Test:

bencode.bencode(None)

expected: b'0:' actual:

>>> bencode.bencode(None)
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "./.env/lib/python3.8/site-packages/bencode/__init__.py", line 304, in bencode
   encode_func[type(value)](value, r)
KeyError: <class 'NoneType'>

CrazyLionHeart avatar May 27 '20 22:05 CrazyLionHeart

I'm not sure how we should be handling types not listed in the bencode specification. Internal type conversions that aren't reversible might not be expected by some users (bool and tuple also have this issue).

Moving forward maybe there should be a flag or separate method to use type conversions?


expected: b'0:'

Not sure encoding None to an empty string is the best option here. Would b'i0e' (0, False) be a better fit?

fuzeman avatar May 28 '20 06:05 fuzeman

Stumbled upon "KeyError: <class 'float'>" and added code to handle data of type FLOAT.

cisene avatar Jul 11 '23 10:07 cisene