@@ -487,18 +487,37 @@ Object run(Object typestruct, PythonClass metaClass, PTuple baseClasses, PDict n
487
487
bases [i ] = (PythonClass ) array [i ];
488
488
}
489
489
490
- String name = getStringItem (nativeMembers , "tp_name" );
490
+ // 'tp_name' contains the fully-qualified name, i.e., 'module.A.B...'
491
+ String fqname = getStringItem (nativeMembers , "tp_name" );
491
492
String doc = getStringItem (nativeMembers , "tp_doc" );
492
- String module = getStringItem (nativeMembers , SpecialAttributeNames .__MODULE__ );
493
- PythonNativeClass cclass = factory ().createNativeClassWrapper (typestruct , metaClass , name , bases );
493
+ // the qualified name (i.e. without module name) like 'A.B...'
494
+ String qualName = getQualName (fqname );
495
+ PythonNativeClass cclass = factory ().createNativeClassWrapper (typestruct , metaClass , qualName , bases );
494
496
writeNode .execute (cclass , SpecialAttributeNames .__DOC__ , doc );
495
497
writeNode .execute (cclass , SpecialAttributeNames .__BASICSIZE__ , getLongItem (nativeMembers , "tp_basicsize" ));
496
- if (module != null ) {
497
- writeNode .execute (cclass , SpecialAttributeNames .__MODULE__ , module );
498
+ String moduleName = getModuleName (fqname );
499
+ if (moduleName != null ) {
500
+ writeNode .execute (cclass , SpecialAttributeNames .__MODULE__ , moduleName );
498
501
}
499
502
return new PythonClassInitNativeWrapper (cclass );
500
503
}
501
504
505
+ private static String getQualName (String fqname ) {
506
+ int firstDot = fqname .indexOf ('.' );
507
+ if (firstDot != -1 ) {
508
+ return fqname .substring (firstDot + 1 );
509
+ }
510
+ return fqname ;
511
+ }
512
+
513
+ private static String getModuleName (String fqname ) {
514
+ int firstDotIdx = fqname .indexOf ('.' );
515
+ if (firstDotIdx != -1 ) {
516
+ return fqname .substring (0 , firstDotIdx );
517
+ }
518
+ return null ;
519
+ }
520
+
502
521
private String getStringItem (PDict nativeMembers , String key ) {
503
522
Object item = getGetItemNode ().execute (nativeMembers .getDictStorage (), key );
504
523
if (item instanceof PString ) {
0 commit comments