bencode.py
bencode.py copied to clipboard
Encoder does not support base type - None
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'>
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?
Stumbled upon "KeyError: <class 'float'>" and added code to handle data of type FLOAT.