From 467b48e8642bf0e211fd7611ad83903ad2a8a761 Mon Sep 17 00:00:00 2001 From: Evert Lammerts Date: Fri, 26 Jun 2026 16:29:01 +0200 Subject: [PATCH] Drop pybind11 module_local() from bound-type registrations Remove the 6 py::module_local() annotations (DuckDBPyConnection, Statement, Expression, Relation, Type class_ registrations + the token_type enum). --- src/duckdb_py/duckdb_python.cpp | 2 +- src/duckdb_py/pyconnection.cpp | 4 ++-- src/duckdb_py/pyexpression/initialize.cpp | 3 +-- src/duckdb_py/pyrelation/initialize.cpp | 2 +- src/duckdb_py/pystatement.cpp | 3 +-- src/duckdb_py/typing/pytype.cpp | 2 +- 6 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/duckdb_py/duckdb_python.cpp b/src/duckdb_py/duckdb_python.cpp index 7683627f..5a8506f9 100644 --- a/src/duckdb_py/duckdb_python.cpp +++ b/src/duckdb_py/duckdb_python.cpp @@ -1106,7 +1106,7 @@ PYBIND11_MODULE(DUCKDB_PYTHON_LIB_NAME, m) { // NOLINT "Tokenizes a SQL string, returning a list of (position, type) tuples that can be " "used for e.g., syntax highlighting", py::arg("query")); - py::enum_(m, "token_type", py::module_local()) + py::enum_(m, "token_type") .value("identifier", PySQLTokenType::PY_SQL_TOKEN_IDENTIFIER) .value("numeric_const", PySQLTokenType::PY_SQL_TOKEN_NUMERIC_CONSTANT) .value("string_const", PySQLTokenType::PY_SQL_TOKEN_STRING_CONSTANT) diff --git a/src/duckdb_py/pyconnection.cpp b/src/duckdb_py/pyconnection.cpp index 5146b38c..1b7aba5f 100644 --- a/src/duckdb_py/pyconnection.cpp +++ b/src/duckdb_py/pyconnection.cpp @@ -454,8 +454,8 @@ DuckDBPyConnection::RegisterScalarUDF(const string &name, const py::function &ud } void DuckDBPyConnection::Initialize(py::handle &m) { - auto connection_module = py::class_>( - m, "DuckDBPyConnection", py::module_local()); + auto connection_module = + py::class_>(m, "DuckDBPyConnection"); connection_module.def("__enter__", &DuckDBPyConnection::Enter) .def("__exit__", &DuckDBPyConnection::Exit, py::arg("exc_type"), py::arg("exc"), py::arg("traceback")); diff --git a/src/duckdb_py/pyexpression/initialize.cpp b/src/duckdb_py/pyexpression/initialize.cpp index c8df85ae..1ea38136 100644 --- a/src/duckdb_py/pyexpression/initialize.cpp +++ b/src/duckdb_py/pyexpression/initialize.cpp @@ -301,8 +301,7 @@ static void InitializeImplicitConversion(py::class_>(m, "Expression", py::module_local()); + auto expression = py::class_>(m, "Expression"); InitializeStaticMethods(m); InitializeDunderMethods(expression); diff --git a/src/duckdb_py/pyrelation/initialize.cpp b/src/duckdb_py/pyrelation/initialize.cpp index 7aa3c735..154a1b80 100644 --- a/src/duckdb_py/pyrelation/initialize.cpp +++ b/src/duckdb_py/pyrelation/initialize.cpp @@ -274,7 +274,7 @@ static void InitializeMetaQueries(py::class_ &m) { } void DuckDBPyRelation::Initialize(py::handle &m) { - auto relation_module = py::class_(m, "DuckDBPyRelation", py::module_local()); + auto relation_module = py::class_(m, "DuckDBPyRelation"); InitializeReadOnlyProperties(relation_module); InitializeAggregates(relation_module); InitializeWindowOperators(relation_module); diff --git a/src/duckdb_py/pystatement.cpp b/src/duckdb_py/pystatement.cpp index cbf254ce..c58df10d 100644 --- a/src/duckdb_py/pystatement.cpp +++ b/src/duckdb_py/pystatement.cpp @@ -15,8 +15,7 @@ static void InitializeReadOnlyProperties(py::class_>(m, "Statement", py::module_local()); + auto relation_module = py::class_>(m, "Statement"); InitializeReadOnlyProperties(relation_module); } diff --git a/src/duckdb_py/typing/pytype.cpp b/src/duckdb_py/typing/pytype.cpp index a9944af4..fef05918 100644 --- a/src/duckdb_py/typing/pytype.cpp +++ b/src/duckdb_py/typing/pytype.cpp @@ -327,7 +327,7 @@ static LogicalType FromObject(const py::object &object) { } void DuckDBPyType::Initialize(py::handle &m) { - auto type_module = py::class_>(m, "DuckDBPyType", py::module_local()); + auto type_module = py::class_>(m, "DuckDBPyType"); type_module.def("__repr__", &DuckDBPyType::ToString, "Stringified representation of the type object"); type_module.def("__eq__", &DuckDBPyType::Equals, "Compare two types for equality", py::arg("other"),