GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — builtin: add dir builtin by sbinet · Pull Request #20 · go-python/gpython

Conversation

@sbinet

@sbinet sbinet commented Aug 30, 2018

Copy link
Copy Markdown
Member

Fixes #12.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@sbinet
builtin: add dir builtin
2b22f72
Fixes #12.
@sbinet

sbinet commented Aug 30, 2018

Copy link
Copy Markdown
Member Author

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 ?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ncw

ncw commented Sep 3, 2018

Copy link
Copy Markdown
Collaborator

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...

gpython/vm/eval.go

Lines 1578 to 1600 in eaa7d28

func callInternal(fn py.Object, args py.Tuple, kwargs py.StringDict, f *py.Frame) (py.Object, error) {
if method, ok := fn.(*py.Method); ok {
switch x := method.Internal(); x {
case py.InternalMethodNone:
case py.InternalMethodGlobals:
return f.Globals, nil
case py.InternalMethodLocals:
f.FastToLocals()
return f.Locals, nil
case py.InternalMethodImport:
return py.BuiltinImport(nil, args, kwargs, f.Globals)
case py.InternalMethodEval:
f.FastToLocals()
return builtinEval(nil, args, kwargs, f.Locals, f.Globals, f.Builtins)
case py.InternalMethodExec:
f.FastToLocals()
return builtinExec(nil, args, kwargs, f.Locals, f.Globals, f.Builtins)
default:
return nil, py.ExceptionNewf(py.SystemError, "Internal method %v not found", x)
}
}
return py.Call(fn, args, kwargs)
}

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@drew-512

drew-512 commented Jan 29, 2022

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@drew-512

drew-512 commented Feb 14, 2022

Copy link
Copy Markdown
Contributor

@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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sbinet

sbinet commented Feb 15, 2022

Copy link
Copy Markdown
Member Author

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

builtin: implement dir

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@sbinet @ncw @drew-512
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.