Ticket #38 (closed defect: worksforme)

Opened 7 years ago

Last modified 7 years ago

PySyck handles non-alphanumeric strings as references, others not

Reported by: thomas@… Owned by: xi
Priority: normal Component: pysyck
Severity: major Keywords: str


>>> 'a' is 'a'
>>> 'a.' is 'a.'
>>> syck.dump(['a', 'a'])
'--- \n- a\n- a\n'
>>> syck.dump(['a.', 'a.'])
'--- \n- &id001 a.\n- *id001\n'

the first two commands show that python itself doesn't distinguish. This is especially problematic since the second case produces a segmentation fault when using syck-0.55-r3 (and surely other older versions).


Change History

comment:1 Changed 7 years ago by xi

  • Status changed from new to closed
  • Resolution set to worksforme

It is possible in PySyck to forbid generating aliases for some specific kinds of identical objects. By default, the following heuristics is used: if an object is a number, or an empty tuple, or an alphanumerical string, aliases are not generated. You can override this by overriding the method Dumper.allow_aliases():

import syck

class MyDumper(syck.Dumper):

    def allow_aliases(self, object):
        if type(object) == str:
            return False
        return syck.Dumper.allow_aliases(self, object)

print syck.dump(['a', 'a'])
print syck.dump(['a.', 'a.'])
print syck.dump(['a', 'a'], Dumper=MyDumper)
print syck.dump(['a.', 'a.'], Dumper=MyDumper)

This code produces:

- a
- a

- &id001 a.
- *id001

- a
- a

- a.
- a.

Add a comment

Modify Ticket

Change Properties
<Author field>
as closed
The resolution will be deleted. Next status will be 'reopened'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.