Closes #5495, but there's a TODO here to improve this further. The current `from_code` implementation feels really indirect.