]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
cast helped + fix some more tests
authorabebus <anamaev263@gmail.com>
Sat, 18 Oct 2025 23:44:53 +0000 (02:44 +0300)
committerabebus <anamaev263@gmail.com>
Sat, 18 Oct 2025 23:44:53 +0000 (02:44 +0300)
                    | python  | cython  | cy / py |
base_row_new        | 1.49859 | 0.20700 | 0.13813 |
row_new             | 1.55294 | 0.23217 | 0.14950 |
base_row_new_proc   | 4.00464 | 1.73984 | 0.43445 |
row_new_proc        | 4.11170 | 1.78038 | 0.43300 |
brow_new_proc_none  | 1.99477 | 0.44120 | 0.22118 |
row_new_proc_none   | 1.99645 | 0.49118 | 0.24602 |
row_dumps           | 0.25204 | 0.47150 | 1.87070 |
row_loads           | 1.60167 | 0.65983 | 0.41196 |
row_values_impl     | 0.40206 | 0.50765 | 1.26261 |
row_iter            | 0.73226 | 0.47736 | 0.65190 |
row_len             | 0.20158 | 0.06363 | 0.31568 |
row_hash            | 0.43993 | 0.23913 | 0.54356 |
getitem             | 0.31425 | 0.16672 | 0.53055 |
getitem_slice       | 0.58969 | 0.43870 | 0.74394 |
get_by_key          | 0.86971 | 0.78178 | 0.89889 |
getattr             | 0.81737 | 0.35774 | 0.43767 |
get_by_key_recreate | 2.70708 | 2.49834 | 0.92289 |
getattr_recreate    | 1.01679 | 0.73802 | 0.72582 |
> mean of values    | —       | —       | 0.60769 |

lib/sqlalchemy/engine/_row_cy.py
setup.py

index c957e5224d54e82f8c90f021e62e56eda80ad78f..91206f634a48937cb20b3e581ded664ebfd8c66f 100644 (file)
@@ -79,13 +79,14 @@ else:
     from cython.cimports.cpython import PyTuple_SET_ITEM
     from cython.cimports.cpython import PySequence_Fast_GET_SIZE
 
-
     @cython.inline
     @cython.cfunc
     @cython.wraparound(False)
     @cython.boundscheck(False)
     @cython.returns(tuple)
-    @cython.locals(res=tuple, proc_size=cython.Py_ssize_t, p=object, value=object)
+    @cython.locals(
+        res=tuple, proc_size=cython.Py_ssize_t, p=object, value=object
+    )
     def _apply_processors(proc: object, data: object) -> Tuple[Any, ...]:
         proc_size = PySequence_Fast_GET_SIZE(proc)
         # TODO: would be nice to do this only on the fist row
@@ -102,7 +103,7 @@ else:
         return res
 
     @cython.inline
-    @cython.cfunc
+    @cython.ccall
     def rowproxy_reconstructor(
         cls: Type[BaseRow], state: Dict[str, Any]
     ) -> BaseRow:
@@ -110,6 +111,7 @@ else:
         obj.__setstate__(state)
         return obj
 
+
 @cython.cclass
 class BaseRow:
     __slots__ = ("_parent", "_data", "_key_to_index")
@@ -121,7 +123,6 @@ class BaseRow:
         )
         _data: Tuple[Any, ...] = cython.declare(tuple, visibility="readonly")
 
-
     def __init__(
         self,
         parent: ResultMetaData,
@@ -153,22 +154,22 @@ class BaseRow:
         self._data = data
 
     if cython.compiled:
-        @cython.inline
-        @cython.cfunc
-        def _getstate_impl(self) -> dict:
+
+        @cython.returns(dict)
+        def __getstate__(self) -> Dict[str, Any]:
             self = cython.cast(BaseRow, self)
             return {"_parent": self._parent, "_data": self._data}
-        
-        def __getstate__(self) -> Dict[str, Any]:
-            return cython.cast(BaseRow, self)._getstate_impl()
 
+        @cython.returns(tuple)
         def __reduce__(self) -> Tuple[Any, Any]:
             self = cython.cast(BaseRow, self)
             return (
                 rowproxy_reconstructor,
-                (self.__class__, self._getstate_impl()),
+                (
+                    self.__class__,
+                    {"_parent": self._parent, "_data": self._data},
+                ),
             )
-        
 
         def __getattribute__(self, name: _KeyType) -> object:
             self = cython.cast(BaseRow, self)
@@ -180,7 +181,10 @@ class BaseRow:
                 if name == "_parent":
                     return self._parent
             if name[0] != "_" and name[-1] != "_":
-                return self._get_by_key_impl(name, True)
+                try:
+                    return self._get_by_key_impl(name, False)
+                except KeyError:
+                    pass
             return object.__getattribute__(self, name)
 
     else:
@@ -226,6 +230,8 @@ class BaseRow:
 
     @cython.cfunc
     @cython.inline
+    @cython.wraparound(False)
+    @cython.boundscheck(False)
     @cython.locals(index=cython.Py_ssize_t)
     def _get_by_key_impl(self, key: _KeyType, attr_err: cython.bint) -> object:
         self = cython.cast(BaseRow, self)
index 9d2e5fb5c1a1208be373cb58772a751dca400de2..bd452a949db8ff650e7d5d47e8652908322f8706 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -49,7 +49,6 @@ if HAS_CYTHON and IS_CPYTHON and not DISABLE_EXTENSION:
     from Cython.Compiler import Options
 
     Options.docstrings = False
-    Options.lookup_module_cpdef = True
     Options.clear_to_none = False
 
     cython_directives: Dict[str, Any] = {