Chris1221 / yamldoc

Dependency-free YAML documentation engine.

Home Page:http://chrisbcole.me/yamldoc/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ValueError: not enough values to unpack (expected 2, got 1)

kayx23 opened this issue · comments

What works

test:
  - a: 3
  - b: 6

What doesn't work

port:
  - 1094
  - 2832

Got the following error msg:

Traceback (most recent call last):
  File "/home/codespace/.local/bin/yamldoc", line 33, in <module>
    sys.exit(load_entry_point('yamldoc==0.1.6', 'console_scripts', 'yamldoc')())
  File "/home/codespace/.local/lib/python3.10/site-packages/yamldoc-0.1.6-py3.10.egg/yamldoc/cli.py", line 14, in cli
  File "/home/codespace/.local/lib/python3.10/site-packages/yamldoc-0.1.6-py3.10.egg/yamldoc/parser.py", line 405, in main
  File "/home/codespace/.local/lib/python3.10/site-packages/yamldoc-0.1.6-py3.10.egg/yamldoc/parser.py", line 72, in parse_yaml
ValueError: not enough values to unpack (expected 2, got 1)

However this is also a valid yaml config that should be supported.

Thank you for the report, I believe this may be related to another issue that I found. I will look into this and get back to you.

Hey @kayx23, thanks again for the report. Would you mind checking if the solution proposed in #11 works for your use-case? I've allowed for array-valued entries.

As a side note, when looking into this I realised that there are a few bits of YAML syntax that I'm not really supporting here, I'll be adding a page that describes the currently unsupported (but of course possible, please continue to request things that are important) pieces of syntax to make things more clear.

As a test case I've added test/yaml/lists.yaml and test/schema/lists.schema.

The example above now renders as the following:

port.yaml:

#' test metadata
port:
  #' this will not be included
  - 1094
  - 2832

yamldoc port.yaml

Key Value Information
port ['1094', '2832'] test metadata

If you add in a schema file with an array type, this is also now recognized:

port.schema:

$schema: "http://json-schema.org/draft-04/schema#"

type: object

properties:
    port:
        type: array

yamldoc port.yaml -s port.schema

Key Value Type Information
port ['1094', '2832'] array test metadata

Btw I coopted that PR to improve testing and fix another issue that I found while investigating this one.

The following will now correctly work:

array_1:
  - 1
  - 2
  - 3

array_2:
  - 4
  - 5
  - 6
Key Value Information
array_1 ['1', '2', '3']
array_2 ['4', '5', '6']

I was previously relying on using the meta-data to "reset" the element detector, but I've relaxed that constraint and now both cases should be covered (subsequent element has meta-data or it doesn't).