44import six
55
66try : # python 3.5+
7- from typing import TypeVar , Callable , Optional , Iterable , Any , Tuple , Mapping , Any , Dict
7+ from typing import TypeVar , Callable , Optional , Iterable , Any , Tuple , Mapping , Any , Dict , Set , List
88 YA = TypeVar ('YA' , bound = 'YamlAble' )
99 T = TypeVar ('T' )
1010except ImportError :
@@ -97,7 +97,7 @@ def is_yaml_tag_supported(cls,
9797def yaml_info (yaml_tag = None , # type: str
9898 yaml_tag_ns = None # type: str
9999 ):
100- # type: (...) -> Callable[[Type[YA], Optional[str], Optional[str] ], Type[YA]]
100+ # type: (...) -> Callable[[Type[YA]], Type[YA]]
101101 """
102102 A simple class decorator to tag a class with a global yaml tag - that way you do not have to call `YamlAble` super
103103 constructor.
@@ -132,7 +132,9 @@ class Foo(YamlAble):
132132 :param yaml_tag_ns: the yaml namespace. It will be appended with '.<cls.__name__>'
133133 :return:
134134 """
135- def f (cls ):
135+ def f (cls # type: Type[YA]
136+ ):
137+ # type: (...) -> Type[YA]
136138 return yaml_info_decorate (cls , yaml_tag = yaml_tag , yaml_tag_ns = yaml_tag_ns )
137139 return f
138140
@@ -180,9 +182,13 @@ class Foo(YamlAble):
180182 if yaml_tag_ns is not None :
181183 if yaml_tag is not None :
182184 raise ValueError ("Only one of 'yaml_tag' and 'yaml_tag_ns' should be provided" )
183- # default: append the class name
185+
186+ # create yaml_tag by appending the class name to the namespace
184187 yaml_tag = yaml_tag_ns + '.' + cls .__name__
185188
189+ elif yaml_tag is None :
190+ raise ValueError ("One non-None `yaml_tag` or `yaml_tag_ns` must be provided." )
191+
186192 if issubclass (cls , YamlObject2 ):
187193 if not yaml_tag .startswith ('!' ):
188194 raise ValueError ("When extending YamlObject2, the `yaml_tag` field should contain the full yaml tag, "
@@ -193,7 +199,7 @@ class Foo(YamlAble):
193199 if yaml_tag .startswith ('!' ):
194200 raise ValueError ("When extending YamlAble, the `yaml_tag` field should only contain the yaml tag suffix, "
195201 "and should therefore NOT start with !" )
196- cls .__yaml_tag_suffix__ = yaml_tag
202+ cls .__yaml_tag_suffix__ = yaml_tag # type: ignore
197203 else :
198204 raise TypeError ("classes tagged with @yaml_info should be subclasses of YamlAble or YamlObject2" )
199205
@@ -263,10 +269,10 @@ def encode_yamlable(dumper,
263269
264270
265271try : # PyYaml 5.1+
266- from yaml import FullLoader , UnsafeLoader
267- ALL_PYYAML_LOADERS = (Loader , SafeLoader , FullLoader , UnsafeLoader )
272+ from yaml import FullLoader
273+ ALL_PYYAML_LOADERS = (Loader , SafeLoader , FullLoader )
268274except ImportError :
269- ALL_PYYAML_LOADERS = (Loader , SafeLoader )
275+ ALL_PYYAML_LOADERS = (Loader , SafeLoader ) # type: ignore
270276
271277
272278ALL_PYYAML_DUMPERS = (Dumper , SafeDumper )
@@ -322,7 +328,7 @@ def _get_all_subclasses(typ, # type: Type[T]
322328 sub_list = typ .__subclasses__ ()
323329
324330 # recurse
325- result = []
331+ result = [] # type: List[Type[T]]
326332 for t in sub_list :
327333 # only keep the origins in the list
328334 # to = get_origin(t) or t
0 commit comments