str() for Symbol

This commit is contained in:
Tony Garnock-Jones 2023-11-10 17:16:03 +01:00
parent 3153dc7c62
commit b192313c94
3 changed files with 11 additions and 4 deletions

View File

@ -52,7 +52,7 @@ def merge2(a, b, merge_embedded=None):
...
ValueError: Cannot merge items
>>> merge2(Record('a', [1, {'x': 2}]), Record('a', [1, {'y': 3}]))
a(1, {'x': 2, 'y': 3})
'a'(1, {'x': 2, 'y': 3})
```

View File

@ -183,6 +183,10 @@ class Symbol(object):
#xyz
>>> Symbol('xyz').name
'xyz'
>>> repr(Symbol('xyz'))
'#xyz'
>>> str(Symbol('xyz'))
'xyz'
>>> import preserves
>>> preserves.stringify(Symbol('xyz'))
'xyz'
@ -228,6 +232,9 @@ class Symbol(object):
def __repr__(self):
return '#' + self.name
def __str__(self):
return self.name
def __preserve_write_binary__(self, encoder):
bs = self.name.encode('utf-8')
encoder.buffer.append(0xb3)
@ -289,7 +296,7 @@ class Record(object):
return self.__hash
def __repr__(self):
return str(self.key) + '(' + ', '.join((repr(f) for f in self.fields)) + ')'
return repr(self.key) + '(' + ', '.join((repr(f) for f in self.fields)) + ')'
def __preserve_write_binary__(self, encoder):
encoder.buffer.append(0xb4)
@ -432,7 +439,7 @@ class RecordConstructorInfo(object):
return self.__hash
def __repr__(self):
return str(self.key) + '/' + str(self.arity)
return repr(self.key) + '/' + str(self.arity)
# Blub blub blub
class ImmutableDict(dict):

View File

@ -2,7 +2,7 @@ from setuptools import setup
setup(
name="preserves",
version="0.992.0",
version="0.992.1",
author="Tony Garnock-Jones",
author_email="tonyg@leastfixedpoint.com",
license="Apache Software License",