Skip to content

Commit 2f9932c

Browse files
author
Sylvain MARIE
committed
Renamed from_yaml_sequence into from_yaml_list for consistency with from_yaml_dict
1 parent 914f20d commit 2f9932c

5 files changed

Lines changed: 19 additions & 19 deletions

File tree

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ Objects can also be loaded from YAML sequences:
125125
Foo - {'a': 0, 'b': 'hey'}
126126
```
127127

128-
The default implementation of `__from_yaml_sequence__` (that you may wish to override in your subclass), is to call
128+
The default implementation of `__from_yaml_list__` (that you may wish to override in your subclass), is to call
129129
the constructor with the sequence contents as positional arguments.
130130

131131
The same also works for scalars:

docs/usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,5 @@ assert b == load(by)
122122

123123
Objects can be loaded from sequences and scalars, in addition to dictionaries. To support this possibility, you simply need to fill the class methods:
124124

125-
- `from_yaml_sequence` for sequences
125+
- `from_yaml_list` for sequences
126126
- `from_yaml_scalar` for scalars

yamlable/base.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class AbstractYamlObject(six.with_metaclass(ABCMeta, object)):
6363
# raise NotImplementedError("Please override `__to_yaml_scalar__` if you wish to dump instances of `%s`"
6464
# " as yaml scalars." % type(self).__name__)
6565
#
66-
# def __to_yaml_sequence__(self):
66+
# def __to_yaml_list__(self):
6767
# # type: (...) -> Sequence[Any]
6868
# """
6969
# Implementors should transform the object into a Sequence containing all information necessary to decode the
@@ -72,7 +72,7 @@ class AbstractYamlObject(six.with_metaclass(ABCMeta, object)):
7272
# Default implementation raises an error.
7373
# :return:
7474
# """
75-
# raise NotImplementedError("Please override `__to_yaml_sequence__` if you wish to dump instances of `%s`"
75+
# raise NotImplementedError("Please override `__to_yaml_list__` if you wish to dump instances of `%s`"
7676
# " as yaml sequences." % type(self).__name__)
7777

7878
def __to_yaml_dict__(self):
@@ -117,10 +117,10 @@ def __from_yaml_scalar__(cls, # type: Type[Y]
117117
return cls(scalar) # type: ignore
118118

119119
@classmethod
120-
def __from_yaml_sequence__(cls, # type: Type[Y]
121-
seq, # type: Sequence[Any]
122-
yaml_tag # type: str
123-
):
120+
def __from_yaml_list__(cls, # type: Type[Y]
121+
seq, # type: Sequence[Any]
122+
yaml_tag # type: str
123+
):
124124
# type: (...) -> Y
125125
"""
126126
Implementors should transform the given Sequence (read from yaml by the pyYaml stack) into an object instance.
@@ -333,7 +333,7 @@ def read_yaml_node_as_yamlobject(
333333

334334
elif isinstance(node, SequenceNode):
335335
constructor_args = read_yaml_node_as_sequence(loader, node)
336-
return cls.__from_yaml_sequence__(constructor_args, yaml_tag=yaml_tag) # type: ignore
336+
return cls.__from_yaml_list__(constructor_args, yaml_tag=yaml_tag) # type: ignore
337337

338338
elif isinstance(node, MappingNode):
339339
constructor_args = read_yaml_node_as_dict(loader, node)

yamlable/main.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ def decode(cls, loader,
416416

417417
elif isinstance(node, SequenceNode):
418418
constructor_args = read_yaml_node_as_sequence(loader, node)
419-
return cls.from_yaml_sequence(yaml_tag_suffix, constructor_args, **kwargs) # type: ignore
419+
return cls.from_yaml_list(yaml_tag_suffix, constructor_args, **kwargs) # type: ignore
420420

421421
elif isinstance(node, MappingNode):
422422
constructor_args = read_yaml_node_as_dict(loader, node)
@@ -456,10 +456,10 @@ def from_yaml_scalar(cls,
456456
"`from_yaml_scalar` to support this feature.")
457457

458458
@classmethod
459-
def from_yaml_sequence(cls,
460-
yaml_tag_suffix, # type: str
461-
seq, # type: Sequence[Any]
462-
**kwargs):
459+
def from_yaml_list(cls,
460+
yaml_tag_suffix, # type: str
461+
seq, # type: Sequence[Any]
462+
**kwargs):
463463
# type: (...) -> Any
464464
"""
465465
Implementing classes should create an object corresponding to the given yaml tag, using the given YAML sequence.
@@ -470,7 +470,7 @@ def from_yaml_sequence(cls,
470470
:return:
471471
"""
472472
raise NotImplementedError("This codec does not support loading objects from sequence. Please override "
473-
"`from_yaml_sequence` to support this feature.")
473+
"`from_yaml_list` to support this feature.")
474474

475475
@classmethod
476476
@abstractmethod

yamlable/tests/test_yamlcodec.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ def to_yaml_dict(cls, obj):
103103

104104
class MyCodec2(MyCodec):
105105
@classmethod
106-
def from_yaml_sequence(cls,
107-
yaml_tag_suffix, # type: str
108-
seq, # type: Sequence[Any]
109-
**kwargs):
106+
def from_yaml_list(cls,
107+
yaml_tag_suffix, # type: str
108+
seq, # type: Sequence[Any]
109+
**kwargs):
110110
# type: (...) -> Any
111111
typ = yaml_tags_to_types[yaml_tag_suffix]
112112
return typ(*seq)

0 commit comments

Comments
 (0)