Skip to content

Commit 2a677e6

Browse files
committed
fix type __str__ and __repr__
1 parent 2b78216 commit 2a677e6

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/org/python/core/PyType.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,18 +1794,26 @@ public int getNumSlots() {
17941794
}
17951795

17961796
@ExposedMethod(names = "__repr__", doc = BuiltinDocs.type___repr___doc)
1797-
final String type_toString() {
1798-
String kind;
1799-
if (!builtin) {
1800-
kind = "class";
1801-
} else {
1802-
kind = "type";
1797+
final String type___repr__() {
1798+
PyObject module = getModule();
1799+
if (module instanceof PyUnicode && !module.toString().equals("builtins")) {
1800+
return module.toString() + "." + getName();
18031801
}
1802+
return getName();
1803+
}
1804+
1805+
@Override
1806+
public PyUnicode __repr__() {
1807+
return new PyUnicode(type___repr__());
1808+
}
1809+
1810+
@ExposedMethod(names = "__str__", doc = BuiltinDocs.type___str___doc)
1811+
final String type_toString() {
18041812
PyObject module = getModule();
1805-
if (module instanceof PyBytes && !module.toString().equals("__builtin__")) {
1806-
return String.format("<%s '%s.%s'>", kind, module.toString(), getName());
1813+
if (module instanceof PyUnicode && !module.toString().equals("builtins")) {
1814+
return String.format("<class '%s.%s'>", module.toString(), getName());
18071815
}
1808-
return String.format("<%s '%s'>", kind, getName());
1816+
return String.format("<class '%s'>", getName());
18091817
}
18101818

18111819
public String toString() {

0 commit comments

Comments
 (0)