googlefonts / googlefonts/glyphsLib

Proper way to copy an object

Open
#443 5 comments 1 reaction 0 assignees View on GitHub
Dominant language
Python
Stars
201
Forks
56
Avg merge
17m
Merged PRs (30d)
1

Description

When using glyphsLib and attempting to use .copy() as I would in Glyphs App, I get the error that `there is no attribute 'copy'`

I have tried importing copy and then using `copy.copy()`, but this yields unexpected behavior. when doing something like:
```
newMaster = copy.copy(font.masters[0])
newMaster.name = "New Master"
font.masters.append(newMaster)
```

The name of the copied master changes to whatever newMaster.name is set to. Essentially no new master is added and instead `font.masters[0]` is renamed.

I am assuming that I am approaching this the wrong way or just missing something, what is the proper way to accomplish this?

Contributor guide

Open the contributing guide

Research direction

Start by tracing the glyphsLib object behind font.masters[0] and how its nested data is copied. Reproduce the shown snippet, then verify that the copied master can be renamed and appended without changing the original or sharing mutable state.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.