BREAKING CHANGE: buffer expose as bytes instead of str#100
BREAKING CHANGE: buffer expose as bytes instead of str#100
Conversation
src/questdb/ingress.pyi
Outdated
|
|
||
| def __str__(self) -> str: | ||
| """Return the constructed buffer as a string. Use for debugging.""" | ||
| def peek(self) -> bytes: |
There was a problem hiding this comment.
In Python it would be idiomatic to use __bytes__ instead.
src/questdb/extra_cpython.pxd
Outdated
| # Ditto, see comment on why not returning a `PyObject` above. | ||
| object PyBytes_FromStringAndSize( | ||
| const char* u, Py_ssize_t size) |
There was a problem hiding this comment.
Remove.
This is already defined in the cython standard lib correctly.
See: https://github.com/cython/cython/blob/master/Cython/Includes/cpython/bytes.pxd where it defines:
bytes PyBytes_FromStringAndSize(char *v, Py_ssize_t len)Usage within ingress.pyx would be something like:
from cpython.bytes cimport PyBytes_FromStringAndSize
src/questdb/ingress.pyi
Outdated
| The current number of bytes currently in the buffer. | ||
|
|
||
| Equivalent (but cheaper) to ``len(str(sender))``. | ||
| Equivalent (but cheaper) to ``len(buffer.peek())``. |
There was a problem hiding this comment.
Update docs to to len(bytes(buffer)).
src/questdb/ingress.pyi
Outdated
|
|
||
| def __str__(self) -> str: | ||
| """Return the constructed buffer as a string. Use for debugging.""" | ||
| def peek(self) -> bytes: |
src/questdb/ingress.pyi
Outdated
| Number of bytes of unsent data in the internal buffer. | ||
|
|
||
| Also see :func:`Sender.__len__`. | ||
| Equivalent (but cheaper) to ``len(sender.peek())``. |
src/questdb/ingress.pyi
Outdated
| """ | ||
|
|
||
| def __len__(self) -> int: | ||
| def peek(self) -> bytes: |
src/questdb/ingress.pyx
Outdated
| The current number of bytes currently in the buffer. | ||
|
|
||
| Equivalent (but cheaper) to ``len(str(sender))``. | ||
| Equivalent (but cheaper) to ``len(buffer.peek())``. |
src/questdb/ingress.pyx
Outdated
| return line_sender_buffer_size(self._impl) | ||
|
|
||
| def __str__(self) -> str: | ||
| def peek(self) -> bytes: |
src/questdb/ingress.pyx
Outdated
| return PyUnicode_FromStringAndSize(utf8, <Py_ssize_t>size) | ||
| cdef inline object _to_bytes(self): | ||
| cdef line_sender_buffer_view view = line_sender_buffer_peek(self._impl) | ||
| if view.len: |
There was a problem hiding this comment.
The if statement is redundant here I think. Impl:
PyObject *
PyBytes_FromStringAndSize(const char *str, Py_ssize_t size)
{
PyBytesObject *op;
if (size < 0) {
PyErr_SetString(PyExc_SystemError,
"Negative size passed to PyBytes_FromStringAndSize");
return NULL;
}
if (size == 1 && str != NULL) {
op = CHARACTER(*str & 255);
assert(_Py_IsImmortal(op));
return (PyObject *)op;
}
if (size == 0) {
return bytes_get_empty(); // <<<<<<<<<<<<<<<<<<<
}
...There was a problem hiding this comment.
Yes, PyBytes_FromStringAndSize handles the <= 0 case.
|
CI needs a tweak as well: I suspect |
Yeah, macOS-12 has been moved |
|
Included In MR #105 |
BREAKING CHANGE: buffer expose as bytes instead of str