summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2018-08-12 14:53:57 +0200
committerAnthon van der Neut <anthon@mnt.org>2018-08-12 14:53:57 +0200
commitbf94f1d0fe36687a09beb7a4d48564127b9d157e (patch)
tree1945392e75b15985dbd68b80590388905be7effe
parent9df115f3280e32fc4a64cafb3645af9574ff9f96 (diff)
downloadruamel.yaml-bf94f1d0fe36687a09beb7a4d48564127b9d157e.tar.gz
get rid of mypy error not MRO-ing subclass MutableSet + MutableMap
-rw-r--r--comments.py20
-rw-r--r--constructor.py25
2 files changed, 42 insertions, 3 deletions
diff --git a/comments.py b/comments.py
index fd28a62..ff0080f 100644
--- a/comments.py
+++ b/comments.py
@@ -656,7 +656,7 @@ class CommentedMap(CommentedBase, MutableMapping):
self.ca.comment[1] = pre_comments
return pre_comments
- def update(self, vals):
+ def update(self, vals): # type: ignore
# type: (Any) -> None
try:
self._od.update(vals)
@@ -947,7 +947,7 @@ class CommentedOrderedMap(CommentedMap):
__slots__ = (Comment.attrib,)
-class CommentedSet(MutableSet, CommentedMap): # NOQA
+class CommentedSet(MutableSet, CommentedBase): # NOQA
__slots__ = Comment.attrib, 'odict'
def __init__(self, values=None):
@@ -957,6 +957,22 @@ class CommentedSet(MutableSet, CommentedMap): # NOQA
if values is not None:
self |= values # type: ignore
+ def _yaml_add_comment(self, comment, key=NoComment, value=NoComment):
+ # type: (Any, Optional[Any], Optional[Any]) -> None
+ """values is set to key to indicate a value attachment of comment"""
+ if key is not NoComment:
+ self.yaml_key_comment_extend(key, comment)
+ return
+ if value is not NoComment:
+ self.yaml_value_comment_extend(value, comment)
+ else:
+ self.ca.comment = comment
+
+ def _yaml_add_eol_comment(self, comment, key):
+ # type: (Any, Any) -> None
+ """add on the value line, with value specified by the key"""
+ self._yaml_add_comment(comment, value=key)
+
def add(self, value):
# type: (Any) -> None
"""Add an element."""
diff --git a/constructor.py b/constructor.py
index 9374b69..bea030c 100644
--- a/constructor.py
+++ b/constructor.py
@@ -267,6 +267,29 @@ class BaseConstructor(object):
else:
raise DuplicateKeyError(*args)
+ def check_set_key(self, node, key_node, setting, key):
+ # type: (Any, Any, Any, Any, Any) -> None
+ if key in setting:
+ if not self.allow_duplicate_keys:
+ args = [
+ 'while constructing a set',
+ node.start_mark,
+ 'found duplicate key "{}"'.format(key),
+ key_node.start_mark,
+ """
+ To suppress this check see:
+ http://yaml.readthedocs.io/en/latest/api.html#duplicate-keys
+ """,
+ """\
+ Duplicate keys will become an error in future releases, and are errors
+ by default when using the new API.
+ """,
+ ]
+ if self.allow_duplicate_keys is None:
+ warnings.warn(DuplicateKeyFutureWarning(*args))
+ else:
+ raise DuplicateKeyError(*args)
+
def construct_pairs(self, node, deep=False):
# type: (Any, bool) -> Any
if not isinstance(node, MappingNode):
@@ -1387,7 +1410,7 @@ class RoundTripConstructor(SafeConstructor):
)
# construct but should be null
value = self.construct_object(value_node, deep=deep) # NOQA
- self.check_mapping_key(node, key_node, typ, key, value)
+ self.check_set_key(node, key_node, typ, key)
if key_node.comment:
typ._yaml_add_comment(key_node.comment, key=key)
if value_node.comment: