Use `dir` builtin, rather than traversing __dict__

This captures attributes inherited from parent classes which the old
method missed. It also respects customizations that objects might make
to their own __dir__ representation. Plus it's shorter!

We also remove the `hasttr('items')` check as this is redundant: the
only place which calls this function already checks for this.