Loader dumper objects api#563
Conversation
1b2f534 to
8f3f979
Compare
682fbb2 to
bfc4e97
Compare
| tag_suffix = None | ||
| if node.tag in self.yaml_constructors: | ||
|
|
||
| if (hasattr(self, '_yaml_constructors') and |
There was a problem hiding this comment.
I would write a wrapper for this. Not sure about a good name.
There was a problem hiding this comment.
Do you plan to add the resolvers and representers in this PR, too?
|
|
||
| if (hasattr(self, '_yaml_constructors') and | ||
| node.tag in self._yaml_constructors and | ||
| self._yaml_constructors[node.tag] is not None |
There was a problem hiding this comment.
Could be easier to delete the constructor when doing add_constructor(tag, None)? Then this check wouldn't be necessary
|
|
||
| if constructor is None and hasattr(self, '_yaml_constructors'): | ||
| for tag_prefix in self._yaml_multi_constructors: | ||
| if tag_prefix is not None and node.tag.startswith(tag_prefix): |
There was a problem hiding this comment.
The None part of the multi_constructors below is not yet supported
There was a problem hiding this comment.
Maybe it would be clearer to do something like this at the start of construct_object:
if self.is_instance_based():
constructors = self._yaml_constructors
multi_constructors = self._yaml_multi_constructors
else:
constructors = self.yaml_constructors
multi_constructors = self.yaml_multi_constructors
Then later code doesn't need to be duplicated
| # loader = Loader.get('cls')(stream) | ||
|
|
||
| else: | ||
| raise AssertionError("Unsupported type for Loader=") |
|
|
||
| if loader.stream is None: | ||
| if stream is None: | ||
| raise AssertionError("load() requires stream=...") |
|
One thing which is not clear from the example is an important design question: will still result in finding a constructor for My proposal would be to only lookup in one or the other - either instance or class based. |
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. |
of course.
integers? |
bfc4e97 to
da67d4b
Compare
instead of just Loader* classes All existing PyYAML usage should not be affected.
2495a71 to
8fb8979
Compare
Depends on #561