New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Loader dumper objects api #563
base: release/6.0
Are you sure you want to change the base?
Conversation
1b2f534
to
8f3f979
Compare
682fbb2
to
bfc4e97
Compare
@@ -76,9 +81,23 @@ def construct_object(self, node, deep=False): | |||
self.recursive_objects[node] = None | |||
constructor = None | |||
tag_suffix = None | |||
if node.tag in self.yaml_constructors: | |||
|
|||
if (hasattr(self, '_yaml_constructors') and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would write a wrapper for this. Not sure about a good name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you plan to add the resolvers and representers in this PR, too?
lib/yaml/constructor.py
Outdated
|
||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The None
part of the multi_constructors below is not yet supported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
lib/yaml/__init__.py
Outdated
# loader = Loader.get('cls')(stream) | ||
|
||
else: | ||
raise AssertionError("Unsupported type for Loader=") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be TypeError
.
lib/yaml/__init__.py
Outdated
|
||
if loader.stream is None: | ||
if stream is None: | ||
raise AssertionError("load() requires stream=...") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be TypeError
.
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