0

Some answers from this question bring very silly ways to cripple the ability to access methods and attributes for instances of objects overriding __dir__ and __getattribute__.

The attributes and methods are still there, but are they really inaccessible?

For example, type(x) still returns the correct answer even if x.__class__ raises AttributeError.

Is there any way to access the hidden methods and attributes?

Community
  • 1
  • 1
Paulo Scardine
  • 73,447
  • 11
  • 124
  • 153

1 Answers1

1

For instances of a new-style class you could do something like this:

object.__getattribute__(instance, '__dict__')

I got the idea while reading a section titled More attribute access for new-style classes in the documentation, where they suggest doing something like that to avoid infinite recursion in its implementation.

martineau
  • 119,623
  • 25
  • 170
  • 301