# HG changeset patch # User Paul Boddie # Date 1479911148 -3600 # Node ID 06c0ef06e967ce4eb1cf01f2b16409ad45e06d1a # Parent a7684997ef7a11555eac21949444ccb80b141a61 Added initial program representation (repr and __repr__) support. diff -r a7684997ef7a -r 06c0ef06e967 lib/__builtins__/identity.py --- a/lib/__builtins__/identity.py Wed Nov 23 15:17:29 2016 +0100 +++ b/lib/__builtins__/identity.py Wed Nov 23 15:25:48 2016 +0100 @@ -3,7 +3,7 @@ """ Identity-related functions. -Copyright (C) 2015 Paul Boddie +Copyright (C) 2015, 2016 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -45,6 +45,10 @@ def issubclass(obj, cls_or_tuple): pass -def repr(obj): pass +def repr(obj): + + "Return a program representation for 'obj'." + + return obj.__repr__() # vim: tabstop=4 expandtab shiftwidth=4 diff -r a7684997ef7a -r 06c0ef06e967 lib/__builtins__/int.py --- a/lib/__builtins__/int.py Wed Nov 23 15:17:29 2016 +0100 +++ b/lib/__builtins__/int.py Wed Nov 23 15:25:48 2016 +0100 @@ -144,6 +144,8 @@ "Return a string representation." return native._int_str(self) + __repr__ = __str__ + def __lshift__(self): pass def __rlshift__(self): pass def __rshift__(self): pass diff -r a7684997ef7a -r 06c0ef06e967 lib/__builtins__/list.py --- a/lib/__builtins__/list.py Wed Nov 23 15:17:29 2016 +0100 +++ b/lib/__builtins__/list.py Wed Nov 23 15:25:48 2016 +0100 @@ -112,12 +112,14 @@ first = False else: b.append(", ") - b.append(self.__get_single_item__(i)) + b.append(repr(self.__get_single_item__(i))) i += 1 b.append("]") return str(b) + __repr__ = __str__ + def __bool__(self): "Lists are true if non-empty." diff -r a7684997ef7a -r 06c0ef06e967 lib/__builtins__/str.py --- a/lib/__builtins__/str.py Wed Nov 23 15:17:29 2016 +0100 +++ b/lib/__builtins__/str.py Wed Nov 23 15:25:48 2016 +0100 @@ -75,8 +75,15 @@ return native._str_len(self) def __str__(self): + "Return a string representation." return self + def __repr__(self): + "Return a string literal representation." + # NOTE: To be implemented with proper quoting. + b = buffer(['"', self, '"']) + return str(b) + def __bool__(self): return native._str_nonempty(self)