dir(entry) not useful on Python 3

Bug #1912279 reported by Colin Watson
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
lazr.restfulclient
Triaged
Low
Unassigned

Bug Description

Python 3 removed support for the very old __members__ and __methods__ attributes, which means that dir() on an Entry is much less useful: you only see lp_attributes, lp_operations, etc., and not the actual introspected names from the web service.

The patch in https://paste.ubuntu.com/p/XQ3vMFtjvW/ makes dir() work, but it has unfortunate consequences when using IPython (e.g. in lp-shell's default behaviour if you have ipython installed): tab-completing the attributes of an entry now takes a very long time (over 10 seconds for lp.me in my tests), because it's trying to fetch all the attributes and do type analysis on them which in some cases involves calling out to the web service. https://github.com/ipython/ipython/issues/9094 describes the tug-of-war at play here.

I'm not sure how to square this circle. The best thing I can think of would be to either exclude self.FIND_COLLECTIONS and self.FIND_ENTRIES from the returned list, or else only include their _link forms: https://paste.ubuntu.com/p/GsKSVtSg6n/ implements the latter approach, and performs reasonably in IPython. I don't love this because it steers people away from the more Pythonic attribute names, but maybe it's the best option.

I suppose we could also implement conditional behaviour based on whether the global __IPYTHON__ name exists, which seems to let us detect whether we're running in IPython. That's pretty nasty, but it would limit the damage. On the other hand I suppose there's no particular reason to assume that this completion behaviour should be limited to IPython, since it's apparently implemented by the separate jedi library.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.