MapPattern with Int() key not working with compound value
See original GitHub issueI’m trying to write a schema using integer keys for a MapPattern, but am running into a snag:
from strictyaml import MapPattern, Int, Str, load, Any
yaml = """
1:
- ABC
2:
- DEF
- GHI
"""
schema1 = MapPattern(Str(), Any())
schema2 = MapPattern(Int(), Any())
print(load(yaml).data)
print(load(yaml, schema1).data)
print(load(yaml, schema2).data) # fails
Result:
OrderedDict([('1', ['ABC']), ('2', ['DEF', 'GHI'])])
OrderedDict([('1', ['ABC']), ('2', ['DEF', 'GHI'])])
Traceback (most recent call last):
File "<untitled>", line 16, in <module>
File ".../Python3.7/strictyaml/parser.py", line 318, in load
File ".../Python3.7/strictyaml/parser.py", line 296, in generic_load
File ".../Python3.7/strictyaml/validators.py", line 17, in __call__
File ".../Python3.7/strictyaml/compound.py", line 75, in validate
File ".../Python3.7/strictyaml/validators.py", line 17, in __call__
File ".../Python3.7/strictyaml/any_validator.py", line 52, in validate
File ".../Python3.7/strictyaml/validators.py", line 17, in __call__
File ".../Python3.7/strictyaml/compound.py", line 257, in validate
File ".../Python3.7/strictyaml/yamllocation.py", line 54, in process
File ".../Python3.7/strictyaml/yamlpointer.py", line 179, in get
File ".../Python3.7/ruamel/yaml/comments.py", line 753, in __getitem__
KeyError: '1'
Am I doing something wrong or are Int() keys not supported?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Why integer key do not work in HashMap? - Stack Overflow
It's because you're not passing a Long type of key when retrieving the value, but an integer instead. These get autoboxed as different ......
Read more >Mappings with defined keys (Map) - HitchDev
Mappings of one value to another are represented by : in YAML and parsed as python dicts. Using StrictYAML's 'Map' you can validate...
Read more >Restrictions on Dictionary Keys and Values - Real Python
Duplicate keys are not allowed. A dictionary maps each key to a corresponding value, so it doesn't make sense to map a particular...
Read more >crdoconnor/strictyaml: Type-safe YAML parser and validator.
StrictYAML is a type-safe YAML parser that parses and validates a restricted subset of the YAML specification. Priorities: Beautiful API; Refusing to parse...
Read more >20. Dictionaries — How to Think Like a Computer Scientist
Dictionaries are yet another kind of compound type. ... The values in a dictionary are accessed with keys, not with indices, so there...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
No, that looks like a bug, and quite an embarrassing one too 😦
I’m going to prioritize fixing this today.
Hi, it’s proving to be a little trickier than I thought to do this but I’m still working on it. Thanks for your patience.
On Sat, 2 May 2020, 15:03 Just van Rossum, notifications@github.com wrote: