takluyver / astsearch

Intelligently search in Python code
https://astsearch.readthedocs.io/en/latest/
MIT License
67 stars 3 forks source link

How to find all mentions of an attribute? #5

Closed vfaronov closed 7 years ago

vfaronov commented 7 years ago

I want to find all places in my codebase where I refer to an attribute named baz on any object. For example:

foo.bar.baz = qux

Can I do that with ASTsearch?

These don’t work:

$ astsearch '?.baz'
$ astsearch '??.baz'

Neither does this (not that it would solve my problem):

$ astsearch '?.bar.baz'

I can find .bar, though:

$ astsearch '?.bar'
./kjT.py
   1|foo.bar.baz = qux
takluyver commented 7 years ago

The issue was that it was only finding attribute access with the load context - where you were reading a value, rather than setting or deleting it.

foo.bar.baz = qux # Not found
qux = foo.bar.baz # Found

I've just pushed a commit to fix it.

vfaronov commented 7 years ago

Thanks!