Last active
September 24, 2021 15:43
-
-
Save N-Coder/a7d63e0e2cc89c7062c75620e1d36802 to your computer and use it in GitHub Desktop.
cppyy __doc__ testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<class cppyy.gbl.Test at 0x55b79cb89e70> {'__module__': '__main__', '__dict__': <attribute '__dict__' of 'Test' objects>, '__weakref__': <attribute '__weakref__' of 'Test' objects>, '__doc__': None, 'templ': cppyy template proxy (internal), '__assign__': <cppyy.CPPOverload object at 0x7f7673be1580>, '__init__': <cppyy.CPPOverload object at 0x7f7673bda840>, 'method': <cppyy.CPPOverload object at 0x7f7673bda8c0>, 'overload': <cppyy.CPPOverload object at 0x7f7673bdd800>, 'field': <cppyy.CPPDataMember object at 0x7f7673bdd830>} | |
Attr 'field' in __dict__, but not accessible via getattr. | |
<class cppyy.gbl.Test at 0x55b79cb89e70> {'__module__': '__main__', '__dict__': <attribute '__dict__' of 'Test' objects>, '__weakref__': <attribute '__weakref__' of 'Test' objects>, '__doc__': 'Description of the class.', 'templ': Description of the templ., '__assign__': <cppyy.CPPOverload object at 0x7f7673be1580>, '__init__': <cppyy.CPPOverload object at 0x7f7673bda840>, 'method': <cppyy.CPPOverload object at 0x7f7673bda8c0>, 'overload': <cppyy.CPPOverload object at 0x7f7673bdd800>, 'field': <cppyy.CPPDataMember object at 0x7f7673bdd830>, 'type_def': <cppyy.TypedefPointerToClass object at 0x7f7673d9f850>} | |
Before: class Test in module | |
class Test(CPPInstance) | |
| Method resolution order: | |
| Test | |
| CPPInstance | |
| builtins.object | |
| | |
| Methods defined here: | |
| | |
| __assign__(...) | |
| Test& Test::operator=(Test&&) | |
| Test& Test::operator=(const Test&) | |
| | |
| __init__(...) | |
| Test::Test(const Test&) | |
| Test::Test(Test&&) | |
| Test::Test() | |
| void __cppyy_internal::init_Test(Test*& self, const std::vector<int>& field = std::vector<int>{}) | |
| | |
| method(...) | |
| int Test::method() | |
| | |
| overload(...) | |
| void Test::overload(int val) | |
| void Test::overload(const std::string& val) | |
| | |
| templ = cppyy template proxy (internal) | |
| ---------------------------------------------------------------------- | |
| Data descriptors defined here: | |
| | |
| __dict__ | |
| dictionary for instance variables (if defined) | |
| | |
| __weakref__ | |
| list of weak references to the object (if defined) | |
| | |
| field | |
| | |
| ---------------------------------------------------------------------- | |
| Methods inherited from CPPInstance: | |
| | |
| __add__(self, value, /) | |
| Return self+value. | |
| | |
| __bool__(self, /) | |
| self != 0 | |
| | |
| __destruct__(...) | |
| call the C++ destructor | |
| | |
| __dispatch__(...) | |
| dispatch to selected overload | |
| | |
| __eq__(self, value, /) | |
| Return self==value. | |
| | |
| __ge__(self, value, /) | |
| Return self>=value. | |
| | |
| __getitem__(...) | |
| pointer dereferencing | |
| | |
| __gt__(self, value, /) | |
| Return self>value. | |
| | |
| __hash__(self, /) | |
| Return hash(self). | |
| | |
| __invert__(self, /) | |
| ~self | |
| | |
| __le__(self, value, /) | |
| Return self<=value. | |
| | |
| __lt__(self, value, /) | |
| Return self<value. | |
| | |
| __mul__(self, value, /) | |
| Return self*value. | |
| | |
| __ne__(self, value, /) | |
| Return self!=value. | |
| | |
| __neg__(self, /) | |
| -self | |
| | |
| __pos__(self, /) | |
| +self | |
| | |
| __radd__(self, value, /) | |
| Return value+self. | |
| | |
| __repr__(self, /) | |
| Return repr(self). | |
| | |
| __rmul__(self, value, /) | |
| Return value*self. | |
| | |
| __rsub__(self, value, /) | |
| Return value-self. | |
| | |
| __rtruediv__(self, value, /) | |
| Return value/self. | |
| | |
| __smartptr__(...) | |
| get associated smart pointer, if any | |
| | |
| __str__(self, /) | |
| Return str(self). | |
| | |
| __sub__(self, value, /) | |
| Return self-value. | |
| | |
| __truediv__(self, value, /) | |
| Return self/value. | |
| | |
| ---------------------------------------------------------------------- | |
| Static methods inherited from CPPInstance: | |
| | |
| __new__(*args, **kwargs) from cppyy.CPPScope | |
| Create and return a new object. See help(type) for accurate signature. | |
| | |
| ---------------------------------------------------------------------- | |
| Data descriptors inherited from CPPInstance: | |
| | |
| __python_owns__ | |
| If true, python manages the life time of this object | |
After: class Test in module | |
class Test(CPPInstance) | |
| Description of the class. | |
| | |
| Method resolution order: | |
| Test | |
| CPPInstance | |
| builtins.object | |
| | |
| Methods defined here: | |
| | |
| __assign__(...) | |
| Test& Test::operator=(Test&&) | |
| Test& Test::operator=(const Test&) | |
| | |
| __init__(...) | |
| Test::Test(const Test&) | |
| Test::Test(Test&&) | |
| Test::Test() | |
| void __cppyy_internal::init_Test(Test*& self, const std::vector<int>& field = std::vector<int>{}) | |
| | |
| method(...) | |
| Description of the method. | |
| | |
| overload(...) | |
| Description of the overload. | |
| | |
| templ = Description of the templ. | |
| Description of the templ. | |
| | |
| ---------------------------------------------------------------------- | |
| Data descriptors defined here: | |
| | |
| __dict__ | |
| dictionary for instance variables (if defined) | |
| | |
| __weakref__ | |
| list of weak references to the object (if defined) | |
| | |
| field | |
| Description of the field. | |
| | |
| ---------------------------------------------------------------------- | |
| Data and other attributes defined here: | |
| | |
| type_def = <cppyy.TypedefPointerToClass object> | |
| Description of the type_def. | |
| | |
| | |
| ---------------------------------------------------------------------- | |
| Methods inherited from CPPInstance: | |
| | |
| __add__(self, value, /) | |
| Return self+value. | |
| | |
| __bool__(self, /) | |
| self != 0 | |
| | |
| __destruct__(...) | |
| call the C++ destructor | |
| | |
| __dispatch__(...) | |
| dispatch to selected overload | |
| | |
| __eq__(self, value, /) | |
| Return self==value. | |
| | |
| __ge__(self, value, /) | |
| Return self>=value. | |
| | |
| __getitem__(...) | |
| pointer dereferencing | |
| | |
| __gt__(self, value, /) | |
| Return self>value. | |
| | |
| __hash__(self, /) | |
| Return hash(self). | |
| | |
| __invert__(self, /) | |
| ~self | |
| | |
| __le__(self, value, /) | |
| Return self<=value. | |
| | |
| __lt__(self, value, /) | |
| Return self<value. | |
| | |
| __mul__(self, value, /) | |
| Return self*value. | |
| | |
| __ne__(self, value, /) | |
| Return self!=value. | |
| | |
| __neg__(self, /) | |
| -self | |
| | |
| __pos__(self, /) | |
| +self | |
| | |
| __radd__(self, value, /) | |
| Return value+self. | |
| | |
| __repr__(self, /) | |
| Return repr(self). | |
| | |
| __rmul__(self, value, /) | |
| Return value*self. | |
| | |
| __rsub__(self, value, /) | |
| Return value-self. | |
| | |
| __rtruediv__(self, value, /) | |
| Return value/self. | |
| | |
| __smartptr__(...) | |
| get associated smart pointer, if any | |
| | |
| __str__(self, /) | |
| Return str(self). | |
| | |
| __sub__(self, value, /) | |
| Return self-value. | |
| | |
| __truediv__(self, value, /) | |
| Return self/value. | |
| | |
| ---------------------------------------------------------------------- | |
| Static methods inherited from CPPInstance: | |
| | |
| __new__(*args, **kwargs) from cppyy.CPPScope | |
| Create and return a new object. See help(type) for accurate signature. | |
| | |
| ---------------------------------------------------------------------- | |
| Data descriptors inherited from CPPInstance: | |
| | |
| __python_owns__ | |
| If true, python manages the life time of this object |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pydoc | |
from io import StringIO | |
import cppyy | |
import sys | |
cppyy.cppdef(""" | |
class Test { | |
public: | |
typedef Test* type_def; | |
std::vector<int> field; | |
int method() { | |
return 42; | |
} | |
void overload(int val) { | |
std::cout << "got int:" << val << std::endl; | |
} | |
void overload(const std::string &val) { | |
std::cout << "got string:" << val << std::endl; | |
} | |
template<typename T> | |
void templ(const T &val) { | |
std::cout << "got template:" << val << std::endl; | |
} | |
}; | |
""") | |
print(cppyy.gbl.Test, cppyy.gbl.Test.__dict__) | |
old_help = StringIO() | |
pydoc.doc(cppyy.gbl.Test, title='Before: %s', output=old_help) | |
cppyy.gbl.Test.__doc__ = "Description of the class." | |
for mem in ["type_def", "field", "method", "overload", "templ"]: | |
try: | |
attr = getattr(cppyy.gbl.Test, mem, None) | |
if attr is None: | |
attr = cppyy.gbl.Test.__dict__.get(mem, None) | |
if attr is not None: | |
print("Attr '%s' in __dict__, but not accessible via getattr." % mem) | |
attr.__doc__ = "Description of the %s." % mem | |
except Exception as e: | |
print(mem, getattr(cppyy.gbl.Test, mem, None), cppyy.gbl.Test.__dict__.get(mem, None)) | |
print(e) | |
print(cppyy.gbl.Test, cppyy.gbl.Test.__dict__) | |
print(old_help.getvalue()) | |
pydoc.doc(cppyy.gbl.Test, title='After: %s', output=sys.stdout) | |
# class PythonTest: | |
# """ Description of the class. """ | |
# | |
# def method(self): | |
# """ Description of the method. """ | |
# pass | |
# | |
# field = "the field's value" | |
# """ Description of the field. """ | |
# | |
# @property | |
# def property(self): | |
# """ Description of the property. """ | |
# return {} | |
# | |
# help(PythonTest) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment