Skip to content

Commit d662ff4

Browse files
committed
Fixed a few names and imports, and main init file.
1 parent 77b647c commit d662ff4

6 files changed

Lines changed: 25 additions & 23 deletions

File tree

yamlable/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1-
from yamlable.base import AbstractYamlObject, NONE_IGNORE_CHECKS, YT_co
2-
from yamlable.main import YamlObject2, YamlAble, yaml_info
1+
from yamlable.base import AbstractYamlObject, NONE_IGNORE_CHECKS, AYO, read_yaml_node_as_dict
2+
from yamlable.main import YamlCodec, register_yamlable_codec, yaml_info_decorate, yaml_info, YamlAble, YA, \
3+
AbstractYamlAble, YAMLABLE_PREFIX
4+
from yamlable.yaml_objects import YO2, YamlObject2, ABCYAMLMeta, YAMLObjectMetaclassStrict
5+
6+
__all__ = ['base',
7+
'main',
8+
'yaml_objects']

yamlable/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
pass # normal for old versions of typing
1010

1111

12-
YT_co = TypeVar('YT_co', bound='AbstractYamlObject')
12+
AYO = TypeVar('AYO', bound='AbstractYamlObject')
1313

1414

1515
class AbstractYamlObject(ABC):
@@ -30,7 +30,7 @@ def to_yaml_dict(self) -> Dict[str, Any]:
3030

3131
@classmethod
3232
@abstractmethod
33-
def from_yaml_dict(cls: 'Type[YT_co]', dct: Dict, yaml_tag: str) -> YT_co:
33+
def from_yaml_dict(cls: 'Type[AYO]', dct: Dict, yaml_tag: str) -> AYO:
3434
"""
3535
Implementors should transform the given dictionary (read from yaml by the pyYaml stack) into an object instance.
3636
The yaml tag associated to this object, read in the yaml document, is provided in parameter.
@@ -71,7 +71,7 @@ def dumps_yaml(self, **pyyaml_kwargs):
7171
return dump(self, **pyyaml_kwargs)
7272

7373
@classmethod
74-
def loads_yaml(cls: 'Type[YT_co]', yaml_str: str) -> YT_co:
74+
def loads_yaml(cls: 'Type[AYO]', yaml_str: str) -> AYO:
7575
"""
7676
Utility method to
7777
:param yaml_str
@@ -80,7 +80,7 @@ def loads_yaml(cls: 'Type[YT_co]', yaml_str: str) -> YT_co:
8080
return cls.load_yaml(StringIO(yaml_str))
8181

8282
@classmethod
83-
def load_yaml(cls: 'Type[YT_co]', file_path_or_stream: Union[str, TextIOBase]) -> YT_co:
83+
def load_yaml(cls: 'Type[AYO]', file_path_or_stream: Union[str, TextIOBase]) -> AYO:
8484
"""
8585
Parses the given file path or stream as a yaml document with the
8686

yamlable/main.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
1-
from abc import ABCMeta, abstractmethod, ABC
1+
from abc import abstractmethod, ABC
22
from typing import TypeVar, Callable, Optional, Iterable, Any, Tuple
3-
4-
from yaml import Loader, SafeLoader, Dumper, SafeDumper
5-
6-
from yaml_objects import YamlObject2
7-
83
try:
94
from typing import Type
105
except ImportError:
116
pass # normal for old versions of typing
127

13-
14-
from six import add_metaclass
8+
from yaml import Loader, SafeLoader, Dumper, SafeDumper
159

1610
from yamlable.base import AbstractYamlObject, NONE_IGNORE_CHECKS, read_yaml_node_as_dict
11+
from yamlable.yaml_objects import YamlObject2
12+
1713

1814
YAMLABLE_PREFIX = '!yamlable/'
1915

2016

21-
@add_metaclass(ABCMeta)
2217
class AbstractYamlAble(AbstractYamlObject):
2318
"""
2419
The abstract part of YamlAble. It might be useful to inherit if you want to create a super class for several

yamlable/tests/test_yamlable.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pytest
55
from yaml import dump, load
66

7-
from yamlable import YamlAble, yaml_info, YT_co
7+
from yamlable import YamlAble, yaml_info, AYO
88

99

1010
def test_yamlable_incomplete_description():
@@ -16,7 +16,7 @@ def to_yaml_dict(self) -> Dict[str, Any]:
1616
return copy(vars(self))
1717

1818
@classmethod
19-
def from_yaml_dict(cls: 'Type[YT_co]', dct: Dict, yaml_tag: str) -> YT_co:
19+
def from_yaml_dict(cls: 'Type[AYO]', dct: Dict, yaml_tag: str) -> AYO:
2020
return Foo(**dct)
2121

2222
# instantiate
@@ -46,7 +46,7 @@ def to_yaml_dict(self) -> Dict[str, Any]:
4646
return copy(vars(self))
4747

4848
@classmethod
49-
def from_yaml_dict(cls: 'Type[YT_co]', dct: Dict, yaml_tag: str) -> YT_co:
49+
def from_yaml_dict(cls: 'Type[AYO]', dct: Dict, yaml_tag: str) -> AYO:
5050
return Foo(**dct)
5151

5252
# instantiate
@@ -84,7 +84,7 @@ def to_yaml_dict(self) -> Dict[str, Any]:
8484
return copy(vars(self))
8585

8686
@classmethod
87-
def from_yaml_dict(cls: 'Type[YT_co]', dct: Dict, yaml_tag: str) -> YT_co:
87+
def from_yaml_dict(cls: 'Type[AYO]', dct: Dict, yaml_tag: str) -> AYO:
8888
return Foo_Err(**dct)
8989

9090
@classmethod

yamlable/tests/test_yamlobjects.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import pytest
55

6-
from yamlable import YamlObject2, YT_co
6+
from yamlable import YamlObject2, AYO
77

88

99
def test_yamlobject_incomplete_description():
@@ -33,7 +33,7 @@ def to_yaml_dict(self) -> Dict[str, Any]:
3333
return copy(vars(self))
3434

3535
@classmethod
36-
def from_yaml_dict(cls: 'Type[YT_co]', dct: Dict, yaml_tag: str) -> YT_co:
36+
def from_yaml_dict(cls: 'Type[AYO]', dct: Dict, yaml_tag: str) -> AYO:
3737
return Foo(**dct)
3838

3939
# instantiate

yamlable/yaml_objects.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88

99
from yamlable.base import NONE_IGNORE_CHECKS, AbstractYamlObject, read_yaml_node_as_dict
1010

11-
SYO = TypeVar('SYO', bound='YamlObject2')
11+
12+
YO2 = TypeVar('YO2', bound='YamlObject2')
1213

1314

1415
class YAMLObjectMetaclassStrict(YAMLObjectMetaclass):
1516
"""
1617
Improved metaclass for YAMLObject, that raises an error if yaml_tag is not defined
1718
"""
18-
def __init__(cls: 'Type[SYO]', name, bases, kwds):
19+
def __init__(cls: 'Type[YO2]', name, bases, kwds):
1920

2021
# construct as usual
2122
super(YAMLObjectMetaclass, cls).__init__(name, bases, kwds)

0 commit comments

Comments
 (0)