Add a flag "hide magic names" in dir

While I understand the current behavior of dir(), most of the time I use it is to quickly have a glance of the “normal” exposed names.
I would propose to add a keyword-only, default-is-current behavior, flag to allow the caller to show only the “normal” names (i.e. - no dunder stuff).

For the name of the flag, I think this is the most complex thing :slight_smile: and I propose to change the signature to

dir([object], *, show_dunder=True)

Additionally (but I’m not sure about the back-compatibility…), also the __dir__() method should accept the same keyword-only flag.

What do you think about it?

1 Like