Vscode-yaml: Custom tag not working for !!python/name

Created on 19 Oct 2019  ·  10Comments  ·  Source: redhat-developer/vscode-yaml

I am using vscode for editing a project based around mkdocs. The mkdocs config file - mkdocs.yaml is always showing an error from the vscode yaml plug-in.

I tried to set an exceptional format via the settings file but I can't get it to work.

customSettings

Is !!python/name supported as a custom tag?

regards
Steve

Most helpful comment

Actually !! is shorthand for ! try add customtags as below
"tag:yaml.org,2002:python/name:pymdownx.emoji.twemoji"
it works for me

All 10 comments

I'm not sure if I entirely understand custom tags for yaml but I've noticed that if you use one exclamation point (!python/name both in the custom tag and the yaml file) instead of two everything works correctly

I _think_ double exclamation point only works with the parser for tags listed here. I could be wrong though, I'm not intimately familiar with how https://github.com/mulesoft-labs/yaml-ast-parser works

same problem here. came from java library called snakeyaml

yaml example:

!!package.CarWithWheel
map: {id: 3}
part: !!org.yaml.snakeyaml.constructor.Wheel {id: 4}
plate: 12-XP-F4
wheel: {id: 2}
year: '2008'

Also here from

  - pymdownx.emoji:
      emoji_index: !!python/name:pymdownx.emoji.twemoji

Just stumbled over this again, any plans?

No plans as of right now

@JPinkney is there a workaround?

Actually !! is shorthand for ! try add customtags as below
"tag:yaml.org,2002:python/name:pymdownx.emoji.twemoji"
it works for me

@tonny008 awesome, thanks! But if it's a shorthand, the extension should probably support it

@tonny008 Do you have a link for that in the spec? If so then it wouldn't be hard to make it so you can put something like !!python/name and it gets translated automatically

@JPinkney https://yaml.org/spec/1.2/spec.html search for Secondary Handle

The secondary tag handle is written as “!!”. This allows using a compact notation for a single “secondary” name space. By default, the prefix associated with this handle is “tag:yaml.org,2002:”. This prefix is used by the YAML tag repository.

It is possible to override this default behavior by providing an explicit “TAG” directive associating a different prefix for this handle.

so if we see something like !!python/name as a local TAG, we can make it translated automatically.
but it is not a good idea to auto translate, if it meant to be a shorthand for a Global (uri) tag. we need to use the specific uri tag name

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ssbarnea picture ssbarnea  ·  3Comments

shadowzen1978 picture shadowzen1978  ·  7Comments

rylnd picture rylnd  ·  3Comments

joshuaavalon picture joshuaavalon  ·  4Comments

bfelbo picture bfelbo  ·  3Comments