Skip to content

Commit efd96af

Browse files
authored
[MLIR][Python] reland (narrower) type stub generation (#157930)
This a reland of #155741 which was reverted at #157831. This version is narrower in scope - it only turns on automatic stub generation for `MLIRPythonExtension.Core._mlir` and **does not do anything automatically**. Specifically, the only CMake code added to `AddMLIRPython.cmake` is the `mlir_generate_type_stubs` function which is then used only in a manual way. The API for `mlir_generate_type_stubs` is: ``` Arguments: MODULE_NAME: The fully-qualified name of the extension module (used for importing in python). DEPENDS_TARGETS: List of targets these type stubs depend on being built; usually corresponding to the specific extension module (e.g., something like StandalonePythonModules.extension._standaloneDialectsNanobind.dso) and the core bindings extension module (e.g., something like StandalonePythonModules.extension._mlir.dso). OUTPUT_DIR: The root output directory to emit the type stubs into. OUTPUTS: List of expected outputs. DEPENDS_TARGET_SRC_DEPS: List of cpp sources for extension library (for generating a DEPFILE). IMPORT_PATHS: List of paths to add to PYTHONPATH for stubgen. PATTERN_FILE: (Optional) Pattern file (see https://nanobind.readthedocs.io/en/latest/typing.html#pattern-files). Outputs: NB_STUBGEN_CUSTOM_TARGET: The target corresponding to generation which other targets can depend on. ``` Downstream users should use `mlir_generate_type_stubs` in coordination with `declare_mlir_python_sources` to turn on stub generation for their own downstream dialect extensions and upstream dialect extensions if they so choose. Standalone example shows an example. Note, downstream will also need to set `-DMLIR_PYTHON_PACKAGE_PREFIX=...` correctly for their bindings.
1 parent 8693ef1 commit efd96af

File tree

27 files changed

+775
-3213
lines changed

27 files changed

+775
-3213
lines changed

.ci/all_requirements.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ ml-dtypes==0.5.1 ; python_version < "3.13" \
194194
--hash=sha256:d13755f8e8445b3870114e5b6240facaa7cb0c3361e54beba3e07fa912a6e12b \
195195
--hash=sha256:fd918d4e6a4e0c110e2e05be7a7814d10dc1b95872accbf6512b80a109b71ae1
196196
# via -r mlir/python/requirements.txt
197-
nanobind==2.7.0 \
198-
--hash=sha256:73b12d0e751d140d6c1bf4b215e18818a8debfdb374f08dc3776ad208d808e74 \
199-
--hash=sha256:f9f1b160580c50dcf37b6495a0fd5ec61dc0d95dae5f8004f87dd9ad7eb46b34
197+
nanobind==2.9.2 \
198+
--hash=sha256:c37957ffd5eac7eda349cff3622ecd32e5ee1244ecc912c99b5bc8188bafd16e \
199+
--hash=sha256:e7608472de99d375759814cab3e2c94aba3f9ec80e62cfef8ced495ca5c27d6e
200200
# via -r mlir/python/requirements.txt
201201
numpy==2.0.2 \
202202
--hash=sha256:0123ffdaa88fa4ab64835dcbde75dcdf89c453c922f18dced6e27c90d1d0ec5a \
@@ -383,6 +383,10 @@ swig==4.3.1 \
383383
--hash=sha256:efec16327029f682f649a26da726bb0305be8800bd0f1fa3e81bf0769cf5b476 \
384384
--hash=sha256:fc496c0d600cf1bb2d91e28d3d6eae9c4301e5ea7a0dec5a4281b5efed4245a8
385385
# via -r lldb/test/requirements.txt
386+
typing-extensions==4.15.0 \
387+
--hash=sha256:0cea48d173cc12fa28ecabc3b837ea3cf6f38c6d1136f85cbaaf598984861466 \
388+
--hash=sha256:f0fa19c6845758ab08074a0cfa8b7aecb71c999ca73d62883bc25cc018c4e548
389+
# via -r mlir/python/requirements.txt
386390
urllib3==2.5.0 \
387391
--hash=sha256:3fc47733c7e419d4bc3f6b3dc2b4f890bb743906a30d56ba4a5bfa4bbff92760 \
388392
--hash=sha256:e6b01673c0fa6a13e374b50871808eb3bf7046c4b125b216f6bf1cc604cff0dc

mlir/cmake/modules/AddMLIRPython.cmake

Lines changed: 103 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,89 @@ function(declare_mlir_python_sources name)
9999
endif()
100100
endfunction()
101101

102+
# Function: mlir_generate_type_stubs
103+
# Turns on automatic type stub generation for extension modules.
104+
# Specifically, performs add_custom_command to run nanobind's stubgen on an extension module.
105+
#
106+
# Arguments:
107+
# MODULE_NAME: The fully-qualified name of the extension module (used for importing in python).
108+
# DEPENDS_TARGETS: List of targets these type stubs depend on being built; usually corresponding to the
109+
# specific extension module (e.g., something like StandalonePythonModules.extension._standaloneDialectsNanobind.dso)
110+
# and the core bindings extension module (e.g., something like StandalonePythonModules.extension._mlir.dso).
111+
# OUTPUT_DIR: The root output directory to emit the type stubs into.
112+
# OUTPUTS: List of expected outputs.
113+
# DEPENDS_TARGET_SRC_DEPS: List of cpp sources for extension library (for generating a DEPFILE).
114+
# IMPORT_PATHS: List of paths to add to PYTHONPATH for stubgen.
115+
# PATTERN_FILE: (Optional) Pattern file (see https://nanobind.readthedocs.io/en/latest/typing.html#pattern-files).
116+
# Outputs:
117+
# NB_STUBGEN_CUSTOM_TARGET: The target corresponding to generation which other targets can depend on.
118+
function(mlir_generate_type_stubs)
119+
cmake_parse_arguments(ARG
120+
""
121+
"MODULE_NAME;OUTPUT_DIR;PATTERN_FILE"
122+
"IMPORT_PATHS;DEPENDS_TARGETS;OUTPUTS;DEPENDS_TARGET_SRC_DEPS"
123+
${ARGN})
124+
125+
# for people doing find_package(nanobind)
126+
if(EXISTS ${nanobind_DIR}/../src/stubgen.py)
127+
set(NB_STUBGEN "${nanobind_DIR}/../src/stubgen.py")
128+
elseif(EXISTS ${nanobind_DIR}/../stubgen.py)
129+
set(NB_STUBGEN "${nanobind_DIR}/../stubgen.py")
130+
# for people using FetchContent_Declare and FetchContent_MakeAvailable
131+
elseif(EXISTS ${nanobind_SOURCE_DIR}/src/stubgen.py)
132+
set(NB_STUBGEN "${nanobind_SOURCE_DIR}/src/stubgen.py")
133+
elseif(EXISTS ${nanobind_SOURCE_DIR}/stubgen.py)
134+
set(NB_STUBGEN "${nanobind_SOURCE_DIR}/stubgen.py")
135+
else()
136+
message(FATAL_ERROR "mlir_generate_type_stubs(): could not locate 'stubgen.py'!")
137+
endif()
138+
139+
file(REAL_PATH "${NB_STUBGEN}" NB_STUBGEN)
140+
set(_import_paths)
141+
foreach(_import_path IN LISTS ARG_IMPORT_PATHS)
142+
file(REAL_PATH "${_import_path}" _import_path)
143+
list(APPEND _import_paths "-i;${_import_path}")
144+
endforeach()
145+
set(_nb_stubgen_cmd
146+
"${Python_EXECUTABLE}"
147+
"${NB_STUBGEN}"
148+
--module
149+
"${ARG_MODULE_NAME}"
150+
"${_import_paths}"
151+
--recursive
152+
--include-private
153+
--output-dir
154+
"${ARG_OUTPUT_DIR}")
155+
if(ARG_PATTERN_FILE)
156+
list(APPEND _nb_stubgen_cmd "-p;${ARG_PATTERN_FILE}")
157+
list(APPEND ARG_DEPENDS_TARGETS "${ARG_PATTERN_FILE}")
158+
endif()
159+
160+
list(TRANSFORM ARG_OUTPUTS PREPEND "${ARG_OUTPUT_DIR}/" OUTPUT_VARIABLE _generated_type_stubs)
161+
set(_depfile "${ARG_OUTPUT_DIR}/${ARG_MODULE_NAME}.d")
162+
if ((NOT EXISTS ${_depfile}) AND ARG_DEPENDS_TARGET_SRC_DEPS)
163+
list(JOIN ARG_DEPENDS_TARGET_SRC_DEPS " " _depfiles)
164+
list(TRANSFORM _generated_type_stubs APPEND ": ${_depfiles}" OUTPUT_VARIABLE _depfiles)
165+
list(JOIN _depfiles "\n" _depfiles)
166+
file(GENERATE OUTPUT "${_depfile}" CONTENT "${_depfiles}")
167+
endif()
168+
169+
message(DEBUG "Generating type-stubs outputs ${_generated_type_stubs}")
170+
add_custom_command(
171+
OUTPUT ${_generated_type_stubs}
172+
COMMAND ${_nb_stubgen_cmd}
173+
WORKING_DIRECTORY "${CMAKE_CURRENT_FUNCTION_LIST_DIR}"
174+
DEPENDS "${ARG_DEPENDS_TARGETS}"
175+
DEPFILE "${_depfile}"
176+
COMMENT "Generating type stubs using: ${_nb_stubgen_cmd}"
177+
)
178+
179+
list(JOIN ARG_DEPENDS_TARGETS "." _name)
180+
set(_name "${_name}.${ARG_MODULE_NAME}.type_stubs")
181+
add_custom_target("${_name}" DEPENDS ${_generated_type_stubs})
182+
set(NB_STUBGEN_CUSTOM_TARGET "${_name}" PARENT_SCOPE)
183+
endfunction()
184+
102185
# Function: declare_mlir_python_extension
103186
# Declares a buildable python extension from C++ source files. The built
104187
# module is considered a python source file and included as everything else.
@@ -678,26 +761,28 @@ function(add_mlir_python_extension libname extname)
678761
# the super project handle compile options as it wishes.
679762
get_property(NB_LIBRARY_TARGET_NAME TARGET ${libname} PROPERTY LINK_LIBRARIES)
680763
target_compile_options(${NB_LIBRARY_TARGET_NAME}
681-
PRIVATE
682-
-Wall -Wextra -Wpedantic
683-
-Wno-c++98-compat-extra-semi
684-
-Wno-cast-qual
685-
-Wno-covered-switch-default
686-
-Wno-nested-anon-types
687-
-Wno-unused-parameter
688-
-Wno-zero-length-array
689-
${eh_rtti_enable})
764+
PRIVATE
765+
-Wall -Wextra -Wpedantic
766+
-Wno-c++98-compat-extra-semi
767+
-Wno-cast-qual
768+
-Wno-covered-switch-default
769+
-Wno-deprecated-literal-operator
770+
-Wno-nested-anon-types
771+
-Wno-unused-parameter
772+
-Wno-zero-length-array
773+
${eh_rtti_enable})
690774

691775
target_compile_options(${libname}
692-
PRIVATE
693-
-Wall -Wextra -Wpedantic
694-
-Wno-c++98-compat-extra-semi
695-
-Wno-cast-qual
696-
-Wno-covered-switch-default
697-
-Wno-nested-anon-types
698-
-Wno-unused-parameter
699-
-Wno-zero-length-array
700-
${eh_rtti_enable})
776+
PRIVATE
777+
-Wall -Wextra -Wpedantic
778+
-Wno-c++98-compat-extra-semi
779+
-Wno-cast-qual
780+
-Wno-covered-switch-default
781+
-Wno-deprecated-literal-operator
782+
-Wno-nested-anon-types
783+
-Wno-unused-parameter
784+
-Wno-zero-length-array
785+
${eh_rtti_enable})
701786
endif()
702787

703788
if(APPLE)

mlir/cmake/modules/MLIRDetectPythonEnv.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ macro(mlir_configure_python_dev_packages)
5454
"extension = '${PYTHON_MODULE_EXTENSION}")
5555

5656
mlir_detect_nanobind_install()
57-
find_package(nanobind 2.4 CONFIG REQUIRED)
57+
find_package(nanobind 2.9 CONFIG REQUIRED)
5858
message(STATUS "Found nanobind v${nanobind_VERSION}: ${nanobind_INCLUDE_DIR}")
5959
message(STATUS "Python prefix = '${PYTHON_MODULE_PREFIX}', "
6060
"suffix = '${PYTHON_MODULE_SUFFIX}', "

mlir/examples/standalone/CMakeLists.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
66
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
77

88
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
9+
set(EXTERNAL_PROJECT_BUILD FALSE)
910
find_package(MLIR REQUIRED CONFIG)
1011

11-
1212
# Define the default argument to use by `lit` when testing.
1313
set(LLVM_LIT_ARGS "-sv" CACHE STRING "Default options for lit")
1414

@@ -27,11 +27,19 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
2727
include(AddMLIR)
2828
include(HandleLLVMOptions)
2929
else()
30+
set(EXTERNAL_PROJECT_BUILD TRUE)
3031
# Build via external projects mechanism
32+
set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/bin)
33+
set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/tools/Standalone/lib)
34+
35+
set(MLIR_BINARY_DIR ${CMAKE_BINARY_DIR})
3136
set(MLIR_MAIN_SRC_DIR ${LLVM_MAIN_SRC_DIR}/../mlir)
3237
set(MLIR_INCLUDE_DIR ${MLIR_MAIN_SRC_DIR}/include)
3338
set(MLIR_GENERATED_INCLUDE_DIR ${LLVM_BINARY_DIR}/tools/mlir/include)
3439
set(MLIR_INCLUDE_DIRS "${MLIR_INCLUDE_DIR};${MLIR_GENERATED_INCLUDE_DIR}")
40+
41+
list(APPEND CMAKE_MODULE_PATH "${MLIR_MAIN_SRC_DIR}/cmake/modules")
42+
list(APPEND CMAKE_MODULE_PATH "${LLVM_MAIN_SRC_DIR}/cmake/modules")
3543
endif()
3644

3745
if(MLIR_ENABLE_BINDINGS_PYTHON)
@@ -54,8 +62,9 @@ if(MLIR_ENABLE_BINDINGS_PYTHON)
5462
message(STATUS "Enabling Python API")
5563
include(MLIRDetectPythonEnv)
5664
mlir_configure_python_dev_packages()
65+
# Note: for EXTERNAL_PROJECT_BUILD this must be set from the command line.
5766
set(MLIR_PYTHON_PACKAGE_PREFIX "mlir_standalone" CACHE STRING "" FORCE)
58-
set(MLIR_BINDINGS_PYTHON_INSTALL_PREFIX "python_packages/standalone/mlir_standalone" CACHE STRING "" FORCE)
67+
set(MLIR_BINDINGS_PYTHON_INSTALL_PREFIX "python_packages/standalone/${MLIR_PYTHON_PACKAGE_PREFIX}" CACHE STRING "" FORCE)
5968
add_subdirectory(python)
6069
endif()
6170
add_subdirectory(test)

mlir/examples/standalone/python/CMakeLists.txt

Lines changed: 79 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ declare_mlir_dialect_python_bindings(
1818
SOURCES
1919
dialects/standalone_pybind11.py
2020
dialects/standalone_nanobind.py
21+
_mlir_libs/_standaloneDialectsNanobind/py.typed
2122
DIALECT_NAME standalone)
2223

2324

@@ -68,16 +69,85 @@ add_mlir_python_common_capi_library(StandalonePythonCAPI
6869
# Instantiation of all Python modules
6970
################################################################################
7071

72+
set(StandalonePythonModules_ROOT_PREFIX "${MLIR_BINARY_DIR}/${MLIR_BINDINGS_PYTHON_INSTALL_PREFIX}")
73+
74+
# Everything here is very tightly coupled. See the ample descriptions at the bottom of
75+
# mlir/python/CMakeLists.txt.
76+
77+
# For a non-external projects build (e.g., installed distro) the type gen targets for the core _mlir module
78+
# need to be re-declared. On the contrary, for an external projects build, the MLIRPythonExtension.Core.type_stub_gen
79+
# target already exists and can just be added to DECLARED_SOURCES (see below).
80+
if(NOT EXTERNAL_PROJECT_BUILD)
81+
set(_core_type_stub_sources
82+
_mlir/__init__.pyi
83+
_mlir/ir.pyi
84+
_mlir/passmanager.pyi
85+
_mlir/rewrite.pyi
86+
)
87+
get_target_property(_core_extension_srcs MLIRPythonExtension.Core INTERFACE_SOURCES)
88+
mlir_generate_type_stubs(
89+
MODULE_NAME _mlir
90+
DEPENDS_TARGETS StandalonePythonModules.extension._mlir.dso
91+
OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/type_stubs/_mlir_libs"
92+
OUTPUTS "${_core_type_stub_sources}"
93+
DEPENDS_TARGET_SRC_DEPS "${_core_extension_srcs}"
94+
IMPORT_PATHS "${StandalonePythonModules_ROOT_PREFIX}/_mlir_libs"
95+
)
96+
set(_mlir_typestub_gen_target "${NB_STUBGEN_CUSTOM_TARGET}")
97+
98+
list(TRANSFORM _core_type_stub_sources PREPEND "_mlir_libs/")
99+
declare_mlir_python_sources(
100+
StandalonePythonExtension.Core.type_stub_gen
101+
ROOT_DIR "${CMAKE_CURRENT_BINARY_DIR}/type_stubs"
102+
ADD_TO_PARENT StandalonePythonSources
103+
SOURCES "${_core_type_stub_sources}"
104+
)
105+
endif()
106+
107+
get_target_property(_standalone_extension_srcs StandalonePythonSources.NanobindExtension INTERFACE_SOURCES)
108+
mlir_generate_type_stubs(
109+
MODULE_NAME mlir_standalone._mlir_libs._standaloneDialectsNanobind
110+
DEPENDS_TARGETS
111+
StandalonePythonModules.extension._mlir.dso
112+
StandalonePythonModules.extension._standaloneDialectsNanobind.dso
113+
OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/type_stubs/_mlir_libs"
114+
OUTPUTS
115+
_standaloneDialectsNanobind/__init__.pyi
116+
_standaloneDialectsNanobind/standalone.pyi
117+
DEPENDS_TARGET_SRC_DEPS "${_standalone_extension_srcs}"
118+
IMPORT_PATHS "${StandalonePythonModules_ROOT_PREFIX}/.."
119+
)
120+
set(_standaloneDialectsNanobind_typestub_gen_target "${NB_STUBGEN_CUSTOM_TARGET}")
121+
122+
declare_mlir_python_sources(
123+
StandalonePythonSources.type_stub_gen
124+
ROOT_DIR "${CMAKE_CURRENT_BINARY_DIR}/type_stubs"
125+
ADD_TO_PARENT StandalonePythonSources
126+
SOURCES
127+
_mlir_libs/_standaloneDialectsNanobind/__init__.pyi
128+
_mlir_libs/_standaloneDialectsNanobind/standalone.pyi
129+
)
130+
set(_declared_sources
131+
StandalonePythonSources
132+
# TODO: Remove this in favor of showing fine grained registration once
133+
# available.
134+
MLIRPythonExtension.RegisterEverything
135+
MLIRPythonSources.Core
136+
MLIRPythonSources.Dialects.builtin
137+
)
138+
# For an external projects build, the MLIRPythonExtension.Core.type_stub_gen
139+
# target already exists and can just be added to DECLARED_SOURCES.
140+
if(EXTERNAL_PROJECT_BUILD)
141+
list(APPEND _declared_sources MLIRPythonExtension.Core.type_stub_gen)
142+
endif()
71143
add_mlir_python_modules(StandalonePythonModules
72-
ROOT_PREFIX "${MLIR_BINARY_DIR}/${MLIR_BINDINGS_PYTHON_INSTALL_PREFIX}"
144+
ROOT_PREFIX "${StandalonePythonModules_ROOT_PREFIX}"
73145
INSTALL_PREFIX "${MLIR_BINDINGS_PYTHON_INSTALL_PREFIX}"
74-
DECLARED_SOURCES
75-
StandalonePythonSources
76-
# TODO: Remove this in favor of showing fine grained registration once
77-
# available.
78-
MLIRPythonExtension.RegisterEverything
79-
MLIRPythonSources.Core
80-
MLIRPythonSources.Dialects.builtin
146+
DECLARED_SOURCES "${_declared_sources}"
81147
COMMON_CAPI_LINK_LIBS
82148
StandalonePythonCAPI
83-
)
149+
)
150+
if(NOT EXTERNAL_PROJECT_BUILD)
151+
add_dependencies(StandalonePythonModules "${_mlir_typestub_gen_target}")
152+
endif()
153+
add_dependencies(StandalonePythonModules "${_standaloneDialectsNanobind_typestub_gen_target}")

mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,9 @@ NB_MODULE(_standaloneDialectsNanobind, m) {
3030
mlirDialectHandleLoadDialect(handle, context);
3131
}
3232
},
33-
nb::arg("context").none() = nb::none(), nb::arg("load") = true);
33+
nb::arg("context").none() = nb::none(), nb::arg("load") = true,
34+
// clang-format off
35+
nb::sig("def register_dialect(context: " MAKE_MLIR_PYTHON_QUALNAME("ir.Context") ", load: bool = True) -> None")
36+
// clang-format on
37+
);
3438
}

mlir/examples/standalone/python/mlir_standalone/_mlir_libs/_standaloneDialectsNanobind/py.typed

Whitespace-only changes.

mlir/include/mlir/Bindings/Python/NanobindAdaptors.h

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,13 @@ class mlir_attribute_subclass : public pure_subclass {
512512
.attr("replace")(superCls.attr("__name__"), captureTypeName);
513513
});
514514
if (getTypeIDFunction) {
515-
def_staticmethod("get_static_typeid",
516-
[getTypeIDFunction]() { return getTypeIDFunction(); });
515+
def_staticmethod(
516+
"get_static_typeid",
517+
[getTypeIDFunction]() { return getTypeIDFunction(); },
518+
// clang-format off
519+
nanobind::sig("def get_static_typeid() -> " MAKE_MLIR_PYTHON_QUALNAME("ir.TypeID"))
520+
// clang-format on
521+
);
517522
nanobind::module_::import_(MAKE_MLIR_PYTHON_QUALNAME("ir"))
518523
.attr(MLIR_PYTHON_CAPI_TYPE_CASTER_REGISTER_ATTR)(
519524
getTypeIDFunction())(nanobind::cpp_function(
@@ -582,8 +587,9 @@ class mlir_type_subclass : public pure_subclass {
582587

583588
// 'isinstance' method.
584589
static const char kIsinstanceSig[] =
585-
"def isinstance(other_type: " MAKE_MLIR_PYTHON_QUALNAME(
586-
"ir") ".Type) -> bool";
590+
// clang-format off
591+
"def isinstance(other_type: " MAKE_MLIR_PYTHON_QUALNAME("ir.Type") ") -> bool";
592+
// clang-format on
587593
def_staticmethod(
588594
"isinstance",
589595
[isaFunction](MlirType other) { return isaFunction(other); },
@@ -599,8 +605,13 @@ class mlir_type_subclass : public pure_subclass {
599605
// `def_property_readonly_static` is not available in `pure_subclass` and
600606
// we do not want to introduce the complexity that pybind uses to
601607
// implement it.
602-
def_staticmethod("get_static_typeid",
603-
[getTypeIDFunction]() { return getTypeIDFunction(); });
608+
def_staticmethod(
609+
"get_static_typeid",
610+
[getTypeIDFunction]() { return getTypeIDFunction(); },
611+
// clang-format off
612+
nanobind::sig("def get_static_typeid() -> " MAKE_MLIR_PYTHON_QUALNAME("ir.TypeID"))
613+
// clang-format on
614+
);
604615
nanobind::module_::import_(MAKE_MLIR_PYTHON_QUALNAME("ir"))
605616
.attr(MLIR_PYTHON_CAPI_TYPE_CASTER_REGISTER_ATTR)(
606617
getTypeIDFunction())(nanobind::cpp_function(
@@ -665,8 +676,9 @@ class mlir_value_subclass : public pure_subclass {
665676

666677
// 'isinstance' method.
667678
static const char kIsinstanceSig[] =
668-
"def isinstance(other_value: " MAKE_MLIR_PYTHON_QUALNAME(
669-
"ir") ".Value) -> bool";
679+
// clang-format off
680+
"def isinstance(other_value: " MAKE_MLIR_PYTHON_QUALNAME("ir.Value") ") -> bool";
681+
// clang-format on
670682
def_staticmethod(
671683
"isinstance",
672684
[isaFunction](MlirValue other) { return isaFunction(other); },

mlir/lib/Bindings/Python/DialectPDL.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ static void populateDialectPDLSubmodule(const nanobind::module_ &m) {
6868
rangeType.def_property_readonly(
6969
"element_type",
7070
[](MlirType type) { return mlirPDLRangeTypeGetElementType(type); },
71+
nb::sig(
72+
"def element_type(self) -> " MAKE_MLIR_PYTHON_QUALNAME("ir.Type")),
7173
"Get the element type.");
7274

7375
//===-------------------------------------------------------------------===//

0 commit comments

Comments
 (0)