1. bobf
  2. bpython
  3. Pull requests

Pull requests

#41 Merged at f5bdfc5
Repository
mjzffr
Branch
default
Repository
bobf
Branch
default

Autocomplete for dictionary keys (Fixes #226)

Author
  1. Maja Frydrychowicz
Reviewers
Description

If d is a dictionary, typing d[ will show a list of key suggestions that you can tab through. The list of suggestions only shows literals. Also works when d is an attribute of some object (e.g. test.d[ will suggest keys for d). Typing anything after the [ turns off the key suggestion: e.g. hitting tab after d['a won't look at dictionary keys and just behaves like previous bpython. If s is some other object, d[s. will get attribute suggestions for s, as in previous bpython.

Summary of changes:

  • cw method allows [ character

  • New complete method in Autocomplete checks if text represents a dictionary and populates self.matches accordingly.

  • show_items method displays suggestions such that anything before the last . or [ or filepath separator is stripped off. Trailing ] is also stripped off.

  • Issues #226: Autocomplete for dictionary keys resolved

Comments (3)

  1. Sebastian Ramacher

    So if played with the pull request a bit. It looks really promising and I think this is a nice addition. I'd love if hitting Tab after d['a would complete further, but if that's not easy to do, I'd merge it the way it is now.

  2. Maja Frydrychowicz author

    I looked into completing string keys and I think it can be done relatively easily. I can't work on it much for the next two weeks or so, but I'll definitely get to it. Does a separate pull request make more sense?