From: Norbert N. <Nor...@gm...> - 2005-01-19 13:51:31
|
Am Mittwoch, 19. Januar 2005 09:34 schrieb Ivan Vilata i Balaguer: > On Mon, Jan 17, 2005 at 09:17:08AM +0100, Norbert Nemec wrote: > > The dictionary should, of course, contain only the names of immediate > > children. It would be __getitem__ that does the '/' parsing and looks up > > the individual steps. dictionary key completion is not an issue. > > I was thinking about the Eric IDE, which somehow manages to complete > values which are only returned by __getitem__ but are not in __dict__ > (don't ask me how it does that). However, __dict__ lookup still works > right in Eric regardless of __getitem__, so it seems that my proposal > would break nothing indeed. I still admit that it might be confusing, > so maybe another new method (e.g. getItem() or getPath()) would be a > better choice. Seems to me that you are cofusing __getattr__ and __getitem__ - the latter has nothing to do with key completion. if you start with something[" and hit TAB, nothing will happen, no matter which IDE or shell you use. Key-completion only works for natural naming. Most shells simply use __dict__ to find out what to offer for completion. It is true, that eric seems to have some additional place to look for but that does not affect this discussion. To sum up: * __dict__ should contain only the immediate children. It is not clear yet, whether it should only contain the pythonic names or all names. * __getitem__ and __getattr__ might well allow additional keys that are not advertised in __dict__: these will not show up for key-completion but they will work nontheless. * it might make sense to do '/' parsing in __getitem__, such that something["abc/djk"] is internally read equivalently to something["abc"]["djk"] or something.abc.djk Of course, "abc/djk" should not appear in __dict__ > > Actually: __dict__ can even contain non-pythonic names. You just cannot > > query them by natural naming, but ipython even shows these names in key > > completion. Anyhow: it certainly would be confusing to have non-pythonic > > names in a __dict__ ... > > I don't see potential trouble, unless you are using __dict__ keys to > build expressions for 'eval' or 'exec', which could be avoided by the > use of __getitem__. The potential confusion would be: >>> mygroup["some non-pythonic name"] = Array(somevalue) >>> mygroup.so<TAB> resulting in >>> mygroup.some non-python name appearing at the command line. Of course this is rather harmless unless you hit return afterwards. But it may be confusing nontheless. Ciao, Norbert -- _________________________________________Norbert Nemec Bernhardstr. 2 ... D-93053 Regensburg Tel: 0941 - 2009638 ... Mobil: 0179 - 7475199 eMail: <No...@Ne...> |