This code in Python:
import yaml
data = {1}
print(yaml.dump(data))
prints:
!!set
1: null
Is it possible to make this output:
!!set
? 1
I think we should be able to do it, because this code:
import yaml
print(yaml.safe_load("""
!!set
? 1"""))
Prints:
{1}
Since sets are simply mappings with null values in YAML, you can customize the output of a set object by overriding
yaml.emitter.Emitter.expect_block_mapping, the block-style emitter of a mapping event, to divert the processing to a custom handler when the event tag is of a set, where the processing logics would be similar to how a regular mapping event is processed byexpect_block_mapping_keymethod, but would force a non-simple key output with a?indicator, and then force the subsequent value state handler to directly move on to the key state handler to avoid the output of anullvalue:so that:
outputs:
and that:
outputs:
Demo: https://replit.com/@blhsing1/PrettyGoldRelationaldatabase