Layers[0] works, layers[:1] does not work

I’m trying to slice the GSGlyph.layers collection to grab multiple layers at once, but it’s returning the wrong layers.

This works great, layers are in the correct order:

print(Glyphs.font.glyphs['A'].layers)
(
	<GSLayer "Display Hairline" (A)>,
	<GSLayer "Display Black" (A)>,
	<GSLayer "Display Hairline" (A)>,
	<GSLayer "Display Black" (A)>,
	<GSLayer "Micro Hairline" (A)>,
	<GSLayer "Micro Black" (A)>
)

This works too, returns the first layer as expected:

print(Glyphs.font.glyphs['A'].layers[0])
<GSLayer "Display Hairline" (A)>

But if I slice the first layer, it returns some other layer instead:

print(Glyphs.font.glyphs['A'].layers[:1])
[<GSLayer "Display Black" (A)>]

And if I slice the whole collection, you can see it’s all in the wrong order:

print(Glyphs.font.glyphs['A'].layers[0:6])
[<GSLayer "Display Black" (A)>, <GSLayer "Display Hairline" (A)>, <GSLayer "Micro Black" (A)>, <GSLayer "Micro Hairline" (A)>, <GSLayer "Display Black" (A)>, <GSLayer "Display Hairline" (A)>]

I would not rely on slicing here. But I have a look at the wrapper and see if I can improve it.

1 Like