# HG changeset patch # User Paul Boddie # Date 1480185609 -3600 # Node ID 6f6aa79f82e5d3f554fbc1337335fdc7899e6241 # Parent e3ec51ee25113a0e503d8015d5e6f71308406bb1 Changed serialisation to handle classes separately, since .__str__ and .__repr__ are interpreted as type.__str__ and type.__repr__ respectively (being provided by the class of ), but these methods would always be unbound even if directly obtained from . diff -r e3ec51ee2511 -r 6f6aa79f82e5 lib/__builtins__/core.py --- a/lib/__builtins__/core.py Sat Nov 26 19:30:47 2016 +0100 +++ b/lib/__builtins__/core.py Sat Nov 26 19:40:09 2016 +0100 @@ -79,13 +79,9 @@ "The class of all classes." - def __str__(self): - - "Return a string representation." + # __str__ and __repr__ are handled by str and repr for classes. - return "" - - __repr__ = __str__ + pass class BaseException: diff -r e3ec51ee2511 -r 6f6aa79f82e5 lib/__builtins__/identity.py --- a/lib/__builtins__/identity.py Sat Nov 26 19:30:47 2016 +0100 +++ b/lib/__builtins__/identity.py Sat Nov 26 19:40:09 2016 +0100 @@ -86,6 +86,14 @@ "Return a program representation for 'obj'." - return obj.__repr__() + # Classes do not provide __repr__ directly. + + if isclass(obj): + return "" + + # Class attributes of instances provide __repr__. + + else: + return obj.__repr__() # vim: tabstop=4 expandtab shiftwidth=4 diff -r e3ec51ee2511 -r 6f6aa79f82e5 lib/__builtins__/str.py --- a/lib/__builtins__/str.py Sat Nov 26 19:30:47 2016 +0100 +++ b/lib/__builtins__/str.py Sat Nov 26 19:40:09 2016 +0100 @@ -19,6 +19,7 @@ this program. If not, see . """ +from __builtins__.identity import isclass from __builtins__.iterator import listiterator from __builtins__.operator import _binary_op, _negate import native @@ -113,6 +114,14 @@ "Return the string representation of 'obj'." - return obj.__str__() + # Classes do not provide __str__ directly. + + if isclass(obj): + return "" + + # Class attributes of instances provide __str__. + + else: + return obj.__str__() # vim: tabstop=4 expandtab shiftwidth=4 diff -r e3ec51ee2511 -r 6f6aa79f82e5 tests/aliases.py --- a/tests/aliases.py Sat Nov 26 19:30:47 2016 +0100 +++ b/tests/aliases.py Sat Nov 26 19:40:09 2016 +0100 @@ -4,54 +4,107 @@ D = C # alias for C +print C # "" +print D # "" + class E: def m(self): return 2 F = E # alias for E +print E # "" +print F # "" + def f(): c = C d = D # C cm = C.m dm = D.m # C.m + print c # "" + print d # "" + print cm # "" + print dm # "" + c = E d = F # E cm = E.m dm = F.m # E.m + print c # "" + print d # "" + print cm # "" + print dm # "" + +f() + Cm = C.m Dm = D.m Em = E.m Fm = F.m +print Cm # "" +print Dm # "" +print Em # "" +print Fm # "" + def g(): Cm = E.m Dm = F.m # E.m + print Cm # "" + print Dm # "" + +g() + def h(): global Em, Fm Em = C.m Fm = D.m # C.m + print Cm # "" + print Dm # "" + +h() + Ci = C() Ei = E() +print Ci # "__main__.C" +print Ei # "__main__.E" + def i(): c = Ci + print c # "__main__.C" c = Ei + print c # "__main__.E" + +i() def j(): global Ei Ei = C() + print Ei # "__main__.C" + +j() L = [] M = [1] +print L # [] +print M # [1] + def k(): c = L + print c # [] + +k() def l(): global M M = [] + print M # [] + +l() +print M # []