question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

What is the rationale for disabling flow-style arrays?

See original GitHub issue

The docs/why/flow-style-removed.md outlines the reasonable argument for disabling flow-style mappings:

  • The difference between inline mappings and explicit mappings is confusing.
  • The curly brackets can denote different things when used as a part of complex toolchain. Notably, Django and Jinja use {{stuff-like-this}} for templating; the python itself uses {stuff-like-this}.

However, I cannot help but notice that all of those arguments are related to flow-style mappings and use only them as examples. Meanwhile, all counterarguments are related to the flow-style arrays, not flow-style mappings.

Is there a reason for disallowing inline arrays? I don’t think anybody uses square brackets for templating, and the both forms of arrays seem natural for me, and easy to understand.

The inspection of code does not show anything problematic: https://github.com/crdoconnor/strictyaml/blob/3b535705d283bcac667e3bdc59be052d9325b13c/strictyaml/parser.py#L210

It seems easy enough to disallow FlowMappingStartToken while tolerating FlowSequenceStartToken.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
Sjlvercommented, Mar 9, 2022

I came across the same problem as @honzajavorek : there seems to be no good way of representing an empty array using StrictYAML.

Admittedly, I haven’t thought much about this… but my favorite solution would be to make an exception to the no-flow-style rule for empty arrays (and maybe empty mappings?). Something like this:

In [1]: import strictyaml

In [2]: strictyaml.load("hello:\n- world").data
Out[2]: {'hello': ['world']}

In [3]: strictyaml.load("hello: [world]").data
FlowMappingDisallowed: While scanning
  in "<unicode string>", line 1, column 8:
    hello: [world]
           ^ (line: 1)
Found ugly disallowed JSONesque flow mapping (surround with ' and ' to make text appear literally)
  in "<unicode string>", line 1, column 9:
    hello: [world]
            ^ (line: 1)

# Currently, this raises FlowMappingDisallowed
In [4]: strictyaml.load("hello: []").data
Out[4]: {'hello': []}

# Currently, this raises YAMLSerializationError: Empty lists are not serializable to StrictYAML unless schema is used.
In [5]: strictyaml.as_document({'hello': []}).as_yaml()
Out[5]: 'hello: []\n'

# Currently, this produces 'hello:\n', which other YAML parsers can't interpret correctly
In [6]: strictyaml.as_document({'hello': []}, strictyaml.Map({'hello': strictyaml.EmptyList()})).as_yaml()
Out[6]: 'hello: []\n'
1reaction
crdoconnorcommented, Sep 12, 2019

Sorry to leave this hanging. I should have responded earlier.

Is there a reason for disallowing inline arrays?

The rationale is pretty much the same as for mapping:

  • There’s already one, obvious way to represent lists - a dash on each line. I tend to follow the rule of there should be one obvious way of doing things (i.e. the zen of python). This also means that a serializer doesn’t have to “think” or be told about whether to represent a list of things using dash notation or flow style - there is only one way of representing a list.

  • Related : a goal of StrictYAML was that it should be viewable and editable by non-programmers. I tend to find that non-programmers get confused by this notation (obvious though it is to programmers).

  • It can be syntactically confusing - especially if you are trying to distinguish strings that have [ and ] vs arrays. I have seen square brackets used for templating as well as several other things that you might want to put in a yaml value.

There are some down sides - notably, that [] is quite a neat way of representing an empty list and for lists that are short it’s nice and compact and readable.

Read more comments on GitHub >

github_iconTop Results From Across the Web

YAML Ain't Markup Language (YAML™) revision 1.2.2
Composing can fail due to any of several reasons, detailed below. ... character stream to effectively “disable” the tag resolution process.
Read more >
postman-security-test-generator/Security Test Environment ... - GitHub
For role based applications, security tests can be a burden to create and maintain. Each endpoint must be tested for every role in...
Read more >
Set storage array to enable or disable Automatic Load Balancing
This command enables or disables the Automatic Load Balancing feature. Syntax. set storageArray autoLoadBalancingEnable=(TRUE | FALSE). Parameter. Parameter ...
Read more >
Teuchos - Trilinos Tools Package: Teuchos_TimeMonitor.cpp ...
285 "ordering of timer creation and destuction or disable the StackedTimer\n" ... 589 for (Array<string>::const_iterator it = globalTimerNames.begin();.
Read more >
Performing Composer-Specific MDS Configurations
Section 23.2.3, "How to Disable Sandbox for an Application" ... For illustration purpose, this example describes a simple scenario where a UserCC tip...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found