Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lamvery/config Crashes Constructor of yaml 'tag:yaml.org,2002:merge' ? #73

Open
sawanoboly opened this issue Apr 3, 2017 · 2 comments

Comments

@sawanoboly
Copy link
Contributor

Here is the code to reproduce.

# Ref: https://github.com/marcy-terui/lamvery/blob/master/lamvery/config.py#L28-L30
import yaml

y = """
def: &default
  foo: bar

pro:
  <<: *default
"""

yaml.load(y)

#=> {'def': {'foo': 'bar'}, 'pro': {'foo': 'bar'}}


from collections import OrderedDict
yaml.add_constructor(
    yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG,
    lambda loader, node: OrderedDict(loader.construct_pairs(node)))

yaml.load(y)
# => ConstructorError: could not determine a constructor for the tag 'tag:yaml.org,2002:merge'
  in "<string>", line 6, column 3:
      <<: *default
      ^
@sawanoboly
Copy link
Contributor Author

サンプルのdice_constructorだとこう言うコケ方にならない、なんでだろう?

http://pyyaml.org/wiki/PyYAMLDocumentation#Constructorsrepresentersresolvers

@marcy-terui
Copy link
Owner

marcy-terui commented Apr 3, 2017

根深そうな問題ですね・・・。順番を保持するためにYAMLでOrderdDictを扱うために入っているコードなんですが、yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG == tag:yaml.org,2002:map なので、tag:yaml.org,2002:merge を足してみたりしたら別のエラーになったり・・・wちょっと調査と試行錯誤が必要そうです。。。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants