backport upstream commit 8081d7b15cf893435c19ea1c0d5e4392a60fe18f

Use dicts and lists where necessary but accept both dicts and lists of
2-tuples everywhere.