@@ -292,7 +292,8 @@ private void createAllSlots(boolean mayAddDict, boolean mayAddWeak) {
292292 * Create the __dict__ descriptor.
293293 */
294294 private void createDictSlot () {
295- dict .__setitem__ ("__dict__" , new PyDataDescr (this , "__dict__" , PyObject .class ) {
295+ String doc = "dictionary for instance variables (if defined)" ;
296+ dict .__setitem__ ("__dict__" , new PyDataDescr (this , "__dict__" , PyObject .class , doc ) {
296297 @ Override
297298 public Object invokeGet (PyObject obj ) {
298299 return obj .getDict ();
@@ -325,7 +326,8 @@ public void invokeDelete(PyObject obj) {
325326 * Create the __weakref__ descriptor.
326327 */
327328 private void createWeakrefSlot () {
328- dict .__setitem__ ("__weakref__" , new PyDataDescr (this , "__weakref__" , PyObject .class ) {
329+ String doc = "list of weak references to the object (if defined)" ;
330+ dict .__setitem__ ("__weakref__" , new PyDataDescr (this , "__weakref__" , PyObject .class , doc ) {
329331 private static final String writeMsg =
330332 "attribute '%s' of '%s' objects is not writable" ;
331333
@@ -484,6 +486,21 @@ protected void init(Class<?> forClass, Set<PyJavaType> needsInners) {
484486 TypeBuilder builder = classToBuilder .get (underlying_class );
485487 name = builder .getName ();
486488 dict = builder .getDict (this );
489+ String doc = builder .getDoc ();
490+ // XXX: Can't create a __doc__ str until the PyBaseString/PyString types are
491+ // created
492+ if (dict .__finditem__ ("__doc__" ) == null && forClass != PyBaseString .class
493+ && forClass != PyString .class ) {
494+ PyObject docObj ;
495+ if (doc != null ) {
496+ docObj = new PyString (doc );
497+ } else {
498+ // XXX: Hack: Py.None may be null during bootstrapping. Most types
499+ // encountered then should have docstrings anyway
500+ docObj = Py .None == null ? new PyString () : Py .None ;
501+ }
502+ dict .__setitem__ ("__doc__" , docObj );
503+ }
487504 setIsBaseType (builder .getIsBaseType ());
488505 instantiable = dict .__finditem__ ("__new__" ) != null ;
489506 fillHasSetAndDelete ();
@@ -1543,14 +1560,15 @@ public void delDict() {
15431560 }
15441561
15451562 /**
1546- * Equivalent of CPython's typeobject type_get_doc; handles __doc__ descriptors.
1563+ * Equivalent of CPython's typeobject.c:: type_get_doc; handles __doc__ descriptors.
15471564 */
1565+ @ ExposedGet (name = "__doc__" )
15481566 public PyObject getDoc () {
1549- PyObject doc = super . getDoc ( );
1550- if (! builtin && doc != null && doc . getType (). lookup ( "__get__" ) ! = null ) {
1551- return doc . __get__ ( null , this ) ;
1567+ PyObject doc = dict . __finditem__ ( "__doc__" );
1568+ if (doc = = null ) {
1569+ return Py . None ;
15521570 }
1553- return doc ;
1571+ return doc . __get__ ( null , this ) ;
15541572 }
15551573
15561574 boolean getUsesObjectGetattribute () {
0 commit comments