mjschultz / py-radix

Python radix tree implementation for IPv4 and IPv6 prefix matching.
Other
119 stars 37 forks source link

Optional args/kwargs are handled incorrectly #32

Closed SantjagoCorkez closed 6 years ago

SantjagoCorkez commented 6 years ago

All those methods with network=None, masklen=None, packed=None signature are improperly handled via C-ext.

While parsing args/kwargs with PyArg_ParseTupleAndKeywords() declaring arg/kwarg's signature with s leads to fill the value with Py_None object while the arg was explicitly passed as None from python. This could be eliminated declaring an arg/kwarg with z - that leads a NULL value in C code instead of Py_None

I've prepared a PR https://github.com/mjschultz/py-radix/pull/31

SantjagoCorkez commented 6 years ago

Also a case that shows the bug:

tr = radix.Radix()
tr.add('127.0.0.1', 8, None)  # causes TypeError of packed parameter (not bytes-like)
mjschultz commented 6 years ago

Should be available via pip install py-radix==0.10.0