File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -197,10 +197,14 @@ class Foo(YamlAble):
197197 raise ValueError ("One non-None `yaml_tag` or `yaml_tag_ns` must be provided." )
198198
199199 if issubclass (cls , YamlObject2 ):
200- if not yaml_tag .startswith ('!' ):
201- raise ValueError ("When extending YamlObject2, the `yaml_tag` field should contain the full yaml tag, "
202- "and should therefore start with !" )
203- cls .yaml_tag = yaml_tag
200+ # Do not support this, because the `YamlObject` metaclass needs the tag to be present BEFORE this decorator is
201+ # even called. So if we are here, it means that we are trying to override a yaml_tag that was already registered
202+ # with pyyaml. Too late!
203+ raise TypeError ("This is not supported" )
204+ # if not yaml_tag.startswith('!'):
205+ # raise ValueError("When extending YamlObject2, the `yaml_tag` field should contain the full yaml tag, "
206+ # "and should therefore start with !")
207+ # cls.yaml_tag = yaml_tag
204208
205209 elif issubclass (cls , YamlAble ):
206210 if yaml_tag .startswith ('!' ):
Original file line number Diff line number Diff line change 11from copy import copy
22try : # python 3.5+
33 from typing import Dict , Any
4- from yamlable import Y
4+ from yamlable import Y , yaml_info
55except ImportError :
66 pass
77
@@ -86,6 +86,14 @@ class AbstractFooE(YamlObject2):
8686 # e.dumps_yaml()
8787
8888
89+ def test_decorator ():
90+ """Test that the decorator can not be used when subclassing CustomFoo3"""
91+ with pytest .raises (TypeError ):
92+ @yaml_info ("!hello_dear" )
93+ class CustomFoo3 (YamlObject2 ):
94+ pass
95+
96+
8997def test_abstract_parent ():
9098 """This tests that we can define an abstract parent class with the YamlAble behaviour and inherit it"""
9199
You can’t perform that action at this time.
0 commit comments