gpython icon indicating copy to clipboard operation
gpython copied to clipboard

builtin: add dir builtin

Open sbinet opened this issue 6 years ago • 5 comments

Fixes go-python/gpython#12.

sbinet avatar Aug 30 '18 13:08 sbinet

this is a WIP.

@ncw, for dir(), I need to be able to get at the content of the local scope. how would I do that from within builtin_dir ?

sbinet avatar Aug 30 '18 13:08 sbinet

The way I've done that in the past, eg for implementing locals() is to implement them as InternalMethods.

Eg here is where the magic is...

https://github.com/go-python/gpython/blob/eaa7d286460777b536b404e09a1bd352f2012a78/vm/eval.go#L1578-L1600

This is where the other magic is!

$ git grep InternalMethodLocals
builtin/builtin.go:             py.MustNewMethod("locals", py.InternalMethodLocals, 0, locals_doc),
py/method.go:   InternalMethodLocals
vm/eval.go:             case py.InternalMethodLocals:

That is the only way I could find to avoid using global variables etc. It might be too limiting eventually.

ncw avatar Sep 03 '18 14:09 ncw

@sbinet after the py.Context merge, I could look at this out if we think dir() is worth it.

drew-512 avatar Jan 29 '22 21:01 drew-512

@sbinet lmk if this is worth adding/improving so we can work towards a cleared PR section. Also, any suggestions on the next version/tag? I think we're worthy of a 0.1 or 1.0 -- open to discussion.

drew-512 avatar Feb 14 '22 18:02 drew-512

in order to get the nice discoverability look and feel of CPython into gpython, having a working dir() builtin is definitely a plus.

but as we survived w/o it for almost 4 years, I don't think cleaning up this PR should be a blocker for the next tagged version of gpython.

sbinet avatar Feb 15 '22 09:02 sbinet