0

I don't want to silence any errors. I want to make a cool package.

Ever do this:

readline.getbegidx()

AttributeError!!!!11!!

"Oh it's actually..."

readline.get_begidx()

I want to make a package that fuzzy matches attributes to callables whenever there's an attribute error. I DONT want to silence any errors or exceptions.

So that when you do:

readline.getbegidx()

It does:

#AttributeError: getbegidx() doesn't exist but get_begidx() does.
#You probably mistyped this attribute name, assuming you meant:
readline.get_begidx()

So what I want to do is to catch every single attribute error and search through the attributes and if the similarity is above something like 98% match, but if not raise the exception, without the user having to do:

try:
except:
try:
except:
try:
except:
...

everywhere.

So I want to:

  1. Detect if an AttributeError occurs
  2. Catch it, get the attribute that was used
  3. If there was a similar attribute, apply that to the original code / replace it
  4. Run the function
Hmm
  • 160
  • 6
  • You could use **__getattr__** for non existent attributes. Then search the dict of the class for an attribute with similar name. – addem Mar 14 '21 at 18:07
  • Thanks! Could you use that in an example? So it's `module.__getatttr__`? I don't think so because it's giving me an error. Yes I plan on using dir(module), but what I'm asking is how to catch every `AttributeError` exception to then run that code. – Hmm Mar 14 '21 at 18:10
  • Here is an answer how to use it in a module: https://stackoverflow.com/a/48916205/8664416 – addem Mar 14 '21 at 18:16
  • Oh I see what you mean. Yeah this will be useful for when I create a new module and in my module I want to maybe get all attributes but what I wanted was to get all attributes of any imported module, rather than my own modules. – Hmm Mar 14 '21 at 18:23

0 Answers0