jds
jds

Reputation: 8279

When debugging in Python, what is "__getattr__" and how can I avoid it?

Let's say I want to step into my function:

-> gene_signature = GeneSignature.from_geo(request.form)
(Pdb) s

What I always get next is:

--Call--
> ../venv/lib/python2.7/site-packages/werkzeug/local.py(335)__getattr__()
-> def __getattr__(self, name):
(Pdb) n
> ../venv/lib/python2.7/site-packages/werkzeug/local.py(336)__getattr__()
-> if name == '__members__':
(Pdb) n
> ../venv/lib/python2.7/site-packages/werkzeug/local.py(338)__getattr__()
-> return getattr(self._get_current_object(), name)
(Pdb) n
--Return--
> ../venv/lib/python2.7/site-packages/werkzeug/local.py(338)__getattr__()->Immutabl...iDict([])
-> return getattr(self._get_current_object(), name)
(Pdb) n

Only after these steps do I get:

--Call--
> ../model/genesignature.py(72)from_geo()
-> @classmethod

What's happening? Can I avoid stepping through this intermediate code?

Upvotes: 0

Views: 473

Answers (1)

Two-Bit Alchemist
Two-Bit Alchemist

Reputation: 18467

Two things:

  1. __getattr__ is the built-in, overrideable method for accessing attributes on objects.

  2. You can avoid stepping into "intermediate code" in the debugger using n rather than s (You do this after the first time but not the first time, so it "steps" into this call.)

Edited to add: It sounds like you are torn between n and s at this point because your break point is in the wrong place. Move it to start inside the function so you aren't stuck either stepping over it or too far into it.

Upvotes: 2

Related Questions