diff options
author | prettyboy <prettyboy@yandex-team.com> | 2023-09-08 00:22:12 +0300 |
---|---|---|
committer | prettyboy <prettyboy@yandex-team.com> | 2023-09-08 00:46:04 +0300 |
commit | 3a6cd865171eed9b89bf536cd242285f8b583a91 (patch) | |
tree | 25e2756c125f7484fb118e0d5724212199662389 /library/cpp/pybind/pod.h | |
parent | 67f3f216950849664a29035458cfaa5d12a62846 (diff) | |
download | ydb-3a6cd865171eed9b89bf536cd242285f8b583a91.tar.gz |
[build/plugins/ytest] Allow prebuilt linters for opensource
Без этого, ydb или не сможет запускать flake8 с помощью ya make.
Или к ним поедет сборка flake8.
Возможно последнее и не так плохо, но сейчас предлагается пока так
Diffstat (limited to 'library/cpp/pybind/pod.h')
-rw-r--r-- | library/cpp/pybind/pod.h | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/library/cpp/pybind/pod.h b/library/cpp/pybind/pod.h new file mode 100644 index 00000000000..90165fdbec6 --- /dev/null +++ b/library/cpp/pybind/pod.h @@ -0,0 +1,53 @@ +#pragma once + +#define PY_SSIZE_T_CLEAN +#include <Python.h> +#include "attr.h" +#include "typedesc.h" + +namespace NPyBind { + struct TPOD { + TPyObjectPtr Dict; + + TPOD() + : Dict(PyDict_New(), true) + { + } + bool SetAttr(const char* name, PyObject* value) { + return PyDict_SetItemString(Dict.Get(), name, value) == 0; + } + PyObject* GetAttr(const char* name) const { + PyObject* res = PyDict_GetItemString(Dict.Get(), name); + Py_XINCREF(res); + return res; + } + }; + + class TPODTraits: public NPyBind::TPythonType<TPOD, TPOD, TPODTraits> { + private: + typedef TPythonType<TPOD, TPOD, TPODTraits> MyParent; + friend class TPythonType<TPOD, TPOD, TPODTraits>; + TPODTraits(); + + public: + static TPOD* GetObject(TPOD& obj) { + return &obj; + } + }; + + template <> + inline bool FromPyObject<TPOD*>(PyObject* obj, TPOD*& res) { + res = TPODTraits::CastToObject(obj); + if (res == nullptr) + return false; + return true; + } + template <> + inline bool FromPyObject<const TPOD*>(PyObject* obj, const TPOD*& res) { + res = TPODTraits::CastToObject(obj); + if (res == nullptr) + return false; + return true; + } + +} |