Source: python-sqt Version: 0.8.0-8 Followup-For: Bug #1098613 Control: tags -1 patch ftbfs
Dear Maintainer, I'm able to replicate this FTBFS locally using a Debian testing (trixie) environment during autopkgtests. After using cython, gcc and Python 3.13 to run a minimized subset of the failing code, I observed a 'PyBytes_Check' assertion failure, and began to suspect some of the typecasting code[1] in the nt_to_aa function that accesses bytearray objects as if they are bytes. Please find attached a patch that rewrites the _helpers.pyx code to construct the relevant objects natively as bytes (immutable), resolving the runtime error while hopefully not degrading performance significantly. Regards, James [1] - https://sources.debian.org/src/python-sqt/0.8.0-8/sqt/_helpers.pyx/#L436-L437
Description: Avoid runtime typecasting of bytearray to bytes Author: James Addison <j...@jp-hosting.net> Bug-Debian: https://bugs.debian.org/1098613 --- --- python-sqt-0.8.0.orig/sqt/_helpers.pyx +++ python-sqt-0.8.0/sqt/_helpers.pyx @@ -402,10 +402,13 @@ def hamming_distance(unicode s, unicode # Lookup table that maps nucleotides to their 2-bit representation # and everything else to 255. -cdef bytearray _nt_trans = bytearray([255]*256) -for frm, to in zip(b'ACGTacgt', b'\x00\x01\x02\x03\x00\x01\x02\x03'): - _nt_trans[frm] = to +def _make_nt_trans(): + table = bytearray([255]*256) + for frm, to in zip(b'ACGTacgt', b'\x00\x01\x02\x03\x00\x01\x02\x03'): + table[frm] = to + return bytes(table) +cdef bytes _nt_trans = _make_nt_trans() # Lookup table that maps 6-bit encoded codons to amino acids def _make_codon_array(stop_aa='*'): @@ -414,9 +417,9 @@ def _make_codon_array(stop_aa='*'): b = codon.encode().translate(_nt_trans) index = b[0] * 16 + b[1] * 4 + b[2] triples[index] = ord(aa) - return triples + return bytes(triples) -cdef bytearray _codon_array = _make_codon_array() +cdef bytes _codon_array = _make_codon_array() def nt_to_aa(s: str): @@ -433,8 +436,8 @@ def nt_to_aa(s: str): cdef int j = 0 cdef int v = 0 cdef unsigned char nt0, nt1, nt2 - cdef char* nt_trans_ptr = <bytes>_nt_trans - cdef char* codon_array_ptr = <bytes>_codon_array + cdef char* nt_trans_ptr = _nt_trans + cdef char* codon_array_ptr = _codon_array cdef bytes s_bytes = s.encode() cdef char* b = s_bytes cdef bytearray result = bytearray([0]*((len(s)+2)//3))