mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-10 21:34:10 -05:00
`dir(object)` is a useful Python function that tells you what attributes and methods an object has. It’s also used by tools like iPython and IDEs for code completion. Some of the attributes of a `JSONModel` are dynamic, based on what fields we expect in the underlying JSON. Therefore they don’t automatically end up in the result of calling `dir`. To get around this we can implement our own `__dir__` method, which also returns the names of the fields we’re expecting the the JSON. Inspired by this Raymond Hettinger tweet: > #python tip: If you add attributes to an API with __getattr__() or > __getattribute__(), remember to update __dir__() to make the extension > introspectable. — https://twitter.com/raymondh/status/1249860863525146624