pyyaml icon indicating copy to clipboard operation
pyyaml copied to clipboard

Loader dumper objects api

Open ingydotnet opened this issue 2 years ago • 3 comments

Depends on #561

ingydotnet avatar Sep 23 '21 19:09 ingydotnet

One thing which is not clear from the example is an important design question: The current PR looks into the instance based constructors (if it is an instance), and if it doesn't find the tag there, it goes on to search in the class based constructors. Meaning, doing

l1 = yaml.SafeLoader()
yaml.add_constructor('!dice', dice_constructor, Loader=yaml.SafeLoader)

will still result in finding a constructor for !dice when using l1

My proposal would be to only lookup in one or the other - either instance or class based. After all we want to get away from the class based global-like thing, and any new stuff would only be supported by the instance API.

perlpunk avatar Sep 24 '21 21:09 perlpunk

One thing which is not clear from the example is an important design question: The current PR looks into the instance based constructors (if it is an instance), and if it doesn't find the tag there, it goes on to search in the class based constructors. Meaning, doing

l1 = yaml.SafeLoader()
yaml.add_constructor('!dice', dice_constructor, Loader=yaml.SafeLoader)

will still result in finding a constructor for !dice when using l1

My proposal would be to only lookup in one or the other - either instance or class based. After all we want to get away from the class based global-like thing, and any new stuff would only be supported by the instance API.

Good point but your instance needs to at least copy over the default class constructors. iow, integers still need to work.

I still have a lot to finish up on this PR. Should have something reviewable by Monday.

ingydotnet avatar Sep 25 '21 12:09 ingydotnet

Good point but your instance needs to at least copy over the default class constructors.

of course.

iow, integers still need to work.

integers?

perlpunk avatar Sep 25 '21 14:09 perlpunk