profile
viewpoint

niemeyer/gopkg 493

Source code for the gopkg.in service.

niemeyer/godeb 287

godeb transforms upstream tarballs for the Go language in deb packages and installs them.

python-constraint/python-constraint 217

Constraint Solving Problem resolver for Python

niemeyer/hsandbox 134

Hacking Sandbox: Multi-language interactive edit [> compile] > run hacking and experimenting tool.

canonical/operator 41

The Python library behind great charms.

niemeyer/golang 37

The Go Language

CanonicalLtd/landscape-client 20

The Landscape Client is the agent which communicates with the Landscape service.

niemeyer/flex 12

Bootstrap of flex project.

pull request commentgo-yaml/yaml

Fix panic on private embedded interface

Hi, yes, and sorry for the delay.

I work here in chunks, when I get a nice slice of calm to focus. I haven't had many of those in the last weeks.

Meanwhile, have you signed the contributor agreement?

It's easy to sign online, and it should read reasonable: https://ubuntu.com/legal/contributors

Thanks for the contribution.

Feresey

comment created time in 14 days

pull request commentgo-check/check

Fix Assert and Check docs about extra args

Thanks!

benhoyt

comment created time in a month

push eventgo-check/check

Ben Hoyt

commit sha 038fdea0a05bc030b0bfda479dc2e08d2220ec74

Fix Assert and Check docs about extra args (#121)

view details

push time in a month

PR merged go-check/check

Fix Assert and Check docs about extra args

I believe the docs about "Extra arguments" are old -- CommentInterface is used instead. This confused me a bit when trying to add additional information to a flaky test.

+6 -4

0 comment

1 changed file

benhoyt

pr closed time in a month

issue commentgo-yaml/yaml

parsing fails when %YAML version is 1.2

Will certainly take that idea into account, thanks for suggesting it.

rogpeppe

comment created time in a month

issue commentgo-yaml/yaml

parsing fails when %YAML version is 1.2

The behavior in v3 is to parse the yes/no literals as booleans only if you explicitly attempt to read them into a bool. Otherwise these are just strings, as 1.2 defines. So it's neither here nor there, but rather a behavior that attempts to smooth out the transition in the least painful way possible.

The behavior when the YAML 1.2 header is observed will be defined at the time we actually introduce support for it. So far requests have been pretty much non-existent.

rogpeppe

comment created time in a month

issue commentgo-yaml/yaml

Please allow the struct tag to be changed to "json"

We will certainly have something along the lines of MarshalWithOptions.. this is already in progress in a different issue and PR, and I'm behind on getting it in.

That's unrelated to supporting compatibility across the two marshalers, though. Their behavior is not the same today, and it's not just a matter of reading it from a different tag and it'll all be alright. If you want to dig, feel free to try to run the json test suite with the yaml marshaler, while simply hacking the tag, and let us know of your experience.

scudette

comment created time in a month

issue commentgo-yaml/yaml

Please allow the struct tag to be changed to "json"

@gophobic This isn't the place for rants.

scudette

comment created time in a month

issue closedgo-yaml/yaml

v3: Can Encode() write 1.0 float as 1.0 (instead of 1)

When printing a float with just a zero after decimal point, the decimal point and the zero is not printed.

func main() {
	m := map[string]interface{}{
		"a": 1.0,
	}
	var buf bytes.Buffer
	enc := goyaml.NewEncoder(&buf)
	if err := enc.Encode(m); err != nil {
		panic(err)
	}
	if err := enc.Close(); err != nil {
		panic(err)
	}
	fmt.Println(string(buf.Bytes()))  // Output: a: 1
        // Expected: a: 1.0
}

I see that internally it does the formatting using strconv.FormatFloat() here. Couldn't figure out a way to do it through strconv.FormatFloat() (convert 1 (float) to "1.0"). If it's possible can it be added to the library?

closed time in a month

shivamMg

issue commentgo-yaml/yaml

v3: Can Encode() write 1.0 float as 1.0 (instead of 1)

You can use yaml.Node directly or via a yaml.Marshaller if you want to fine tune the encoded string or just preserve the original string value. In the specific example you're using a map of interface{}, with a plain 1.0, so it's using the default behavior of the library which is to encode into the shortest human representation of the number.

I realize this may sound a bit controversial because 1 and 1.0 are two different types as far as the yaml specification is concerned, but this was a conscious choice made early on, based on the idea that the only reason one would pick yaml is because it's human-friendly to read and write, and having software with diverging behavior for 1 and 1.0 would go against that.

If you have further questions or more details about your use case, happy to continue the conversation here.

shivamMg

comment created time in a month

issue closedgo-yaml/yaml

How can I preserve the original format?

I use yaml.Unmarshal to Unmarshal a file. image

image

The file is as follows: image

Then I change the struct

image

Then I use Marshal to reverse it: image

The output is as follows: image the output is Completely messed up,Who can tell me How can I preserve the original format? I expect the output looks like that: image Many thanks!

closed time in a month

Alexbyy

issue commentgo-yaml/yaml

How can I preserve the original format?

Your str2 Go literal has invisible trailing spaces:

fmt.Printf("%q\n", str2)

Output:

"   \nkey namespace_name\npattern %s\n"

The yaml encoder currently avoids marshaling it out as a plain scalar because, just like in your Go source code, this makes the data invisible. If the Go string is fixed to not have trailing spaces, the yaml output will look like what you seem to expect.

Alexbyy

comment created time in a month

pull request commentgo-yaml/yaml

Adding EncodeWithComments function

Thanks for raising this. Can you please open an issue about it so we can track the problem independently from this particular PR? I think we don't want a new function just for this, so the fix will likely have a different shape. There's a chance I just misjudged the feature and we don't need that flag at all, or at least we don't need to discard comments with it. Alternatively, we've been looking into adding a more general options mechanism for such cases, but not sure this will even be required here.

Thanks again.

scallister

comment created time in a month

issue commentgo-yaml/yaml

v3: Invalid output (bad indentation) when an indentation indicator/hint is used in a scalar block

Thanks for the report and PR. I'll look into those.

Meanwhile, have you signed the contributor agreement (https://ubuntu.com/legal/contributors)?

It's easy to sign online and the text should be very reasonable hopefully.

abursavich

comment created time in 2 months

issue closedgo-yaml/yaml

First level is indented twice?

Since https://github.com/go-yaml/yaml/commit/a5ece683394c3b88d90572e44d36c93aea492c2c, the first level of my YAML documents is indented with 4 spaces, yet every other level stays at 2: https://play.golang.org/p/UFEafwZx1Wk yields

users:
    - name: Foo
      lastname: Bar
      emails:
        - foo@bar.org
      friends:
        - name: Friend
          lastname: ""
          emails: []
          friends: []
names:
    - test

When i was expecting

users:
  - name: Foo
    lastname: Bar
    emails:
      - foo@bar.org
    friends:
      - name: Friend
        lastname: ""
        emails: []
        friends: []
names:
  - test

closed time in 2 months

xrstf

issue commentgo-yaml/yaml

First level is indented twice?

Orderly and aesthetic pleasing are often subjective, and it's easy to confuse something aesthetic pleasing with something that we're used to because that's how it's been for a while. In practice here, although the configuration says 4, the first output has inconsistent indentations at 6 spaces. That sounds hard to justify as pleasing or orderly, and easy to argue it makes it harder for people to read the input properly. The second output has indentations matching exactly the depth of the data represented at that level. That's why I've accepted the complaints received and fixed this in v3.

xrstf

comment created time in 2 months

issue commentgo-yaml/yaml

How can I preserve the original format?

The yaml package will already format it as suggested automatically, as long as the string contains newlines. The fact this heuristic is not working for your case probably implies that the content being marshaled contains unusual characters that had to be quoted to be parsed properly. Can you please provide a reproducer using https://play.golang.org so we can look into it?

Alexbyy

comment created time in 2 months

issue closedgo-yaml/yaml

v3: dumps indenting not coherent with v2

The way v3 indents dumps by default is different from v2 and I think it shouldn't be:

  • default indenting is now 4 spaces instead of 2
  • list items are now shifted right instead of being vertically aligned with the key
a: Easy! v2
b:
  c: 2
  d:
  - 3
  - 4
a: Easy! v3
b:
    c: 2
    d:
        - 3
        - 4

I know it won't matter but I personally prefer the looks of the first dump.

Also I've seen this change break tests that rely on yaml string equality.

closed time in 2 months

sylr

issue commentgo-yaml/yaml

v3: dumps indenting not coherent with v2

Yes, in v3 we've fixed the indentation so that each level is coherently aligned across all elements and nesting levels. Note in your example how the second output is perfectly aligned according to its depth, while the first is not.

Tests expecting an exact format will indeed break. That's why this was done between v2 and v3 and not inside the release.

sylr

comment created time in 2 months

more