From 19da0a9d8c38ebb23d7d8d91ffdee47fe8ed3b5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Thu, 5 May 2022 13:13:56 +0200 Subject: [PATCH] Minor fixes for typing. --- src/mobase/wrappers/basic_classes.cpp | 8 ++++++ src/mobase/wrappers/pyfiletree.cpp | 27 +++++++------------ src/mobase/wrappers/pyplugins.cpp | 7 ----- .../pybind11_qt/details/pybind11_qt_qlist.h | 4 ++- 4 files changed, 20 insertions(+), 26 deletions(-) diff --git a/src/mobase/wrappers/basic_classes.cpp b/src/mobase/wrappers/basic_classes.cpp index 6a5d52a..55b2d9b 100644 --- a/src/mobase/wrappers/basic_classes.cpp +++ b/src/mobase/wrappers/basic_classes.cpp @@ -665,6 +665,14 @@ namespace mo2::python { void add_iinstallation_manager_classes(py::module_ m) { + // add this here to get proper typing + py::enum_(m, "InstallResult") + .value("SUCCESS", IPluginInstaller::RESULT_SUCCESS) + .value("FAILED", IPluginInstaller::RESULT_FAILED) + .value("CANCELED", IPluginInstaller::RESULT_CANCELED) + .value("MANUAL_REQUESTED", IPluginInstaller::RESULT_MANUALREQUESTED) + .value("NOT_ATTEMPTED", IPluginInstaller::RESULT_NOTATTEMPTED); + py::class_(m, "IInstallationManager") .def("getSupportedExtensions", &IInstallationManager::getSupportedExtensions) diff --git a/src/mobase/wrappers/pyfiletree.cpp b/src/mobase/wrappers/pyfiletree.cpp index d0ad03a..acff7b1 100644 --- a/src/mobase/wrappers/pyfiletree.cpp +++ b/src/mobase/wrappers/pyfiletree.cpp @@ -95,29 +95,21 @@ namespace mo2::python { py::class_>( m, "IFileTree", py::multiple_inheritance()); + // this is FILE_OR_DIRECTORY but as a FileType since we kind of cheat for the + // exposure in Python and this help pybind11 creates proper typing + + const auto FILE_OR_DIRECTORY = static_cast( + FileTreeEntry::FILE_OR_DIRECTORY.toInt()); + // we do not use the enum directly, we will mostly bind the FileTypes // (with an S) py::enum_(fileTreeEntryClass, "FileTypes", py::arithmetic{}) .value("FILE", FileTreeEntry::FileType::FILE) .value("DIRECTORY", FileTreeEntry::FileType::DIRECTORY) - .value("FILE_OR_DIRECTORY", static_cast( - FileTreeEntry::FILE_OR_DIRECTORY.toInt())) + .value("FILE_OR_DIRECTORY", FILE_OR_DIRECTORY) .export_values(); - fileTreeEntryClass - .def_property_readonly_static("FILE", - [](py::object) { - return FileTreeEntry::FILE; - }) - .def_property_readonly_static("DIRECTORY", - [](py::object) { - return FileTreeEntry::DIRECTORY; - }) - .def_property_readonly_static("FILE_OR_DIRECTORY", [](py::object) { - return FileTreeEntry::FILE_OR_DIRECTORY; - }); - fileTreeEntryClass .def("isFile", &FileTreeEntry::isFile) @@ -177,11 +169,10 @@ namespace mo2::python { iFileTreeClass.def("exists", py::overload_cast( &IFileTree::exists, py::const_), - py::arg("path"), - py::arg("type") = IFileTree::FILE_OR_DIRECTORY); + py::arg("path"), py::arg("type") = FILE_OR_DIRECTORY); iFileTreeClass.def( "find", py::overload_cast(&IFileTree::find), - py::arg("path"), py::arg("type") = IFileTree::FILE_OR_DIRECTORY); + py::arg("path"), py::arg("type") = FILE_OR_DIRECTORY); iFileTreeClass.def("pathTo", &IFileTree::pathTo, py::arg("entry"), py::arg("sep") = "\\"); diff --git a/src/mobase/wrappers/pyplugins.cpp b/src/mobase/wrappers/pyplugins.cpp index 36f11ba..86dd6a5 100644 --- a/src/mobase/wrappers/pyplugins.cpp +++ b/src/mobase/wrappers/pyplugins.cpp @@ -96,13 +96,6 @@ namespace mo2::python { // multiple installers void add_iplugininstaller_bindings(pybind11::module_ m) { - py::enum_(m, "InstallResult") - .value("SUCCESS", IPluginInstaller::RESULT_SUCCESS) - .value("FAILED", IPluginInstaller::RESULT_FAILED) - .value("CANCELED", IPluginInstaller::RESULT_CANCELED) - .value("MANUAL_REQUESTED", IPluginInstaller::RESULT_MANUALREQUESTED) - .value("NOT_ATTEMPTED", IPluginInstaller::RESULT_NOTATTEMPTED); - // this is bind but should not be inherited in Python - does not make sense, // having it makes it simpler to bind the Simple and Custom installers py::class_, IPlugin, diff --git a/src/pybind11-qt/include/pybind11_qt/details/pybind11_qt_qlist.h b/src/pybind11-qt/include/pybind11_qt/details/pybind11_qt_qlist.h index 1322149..e640725 100644 --- a/src/pybind11-qt/include/pybind11_qt/details/pybind11_qt_qlist.h +++ b/src/pybind11-qt/include/pybind11_qt/details/pybind11_qt_qlist.h @@ -41,7 +41,9 @@ namespace pybind11::detail::qt { parent); } - PYBIND11_TYPE_CASTER(Type, const_name("Iterable[") + value_conv::name + + // we type these as "Sequence" even if these can be constructed from Iterable, + // otherwise the return type will be typed as "Iterable" which is problematic + PYBIND11_TYPE_CASTER(Type, const_name("Sequence[") + value_conv::name + const_name("]")); };