Title: How to get `globals()` inside Go bounded method? · Issue #211 · go-python/gpython · GitHub
Open Graph Title: How to get `globals()` inside Go bounded method? · Issue #211 · go-python/gpython
X Title: How to get `globals()` inside Go bounded method? · Issue #211 · go-python/gpython
Description: Simple description I cannot find a way to access globals() within a bounded method in GoLang. I expose a type into module, like moduleImpl.Globals["Foo"] = FooType, and add methods to FooType by FooType.Globals["bar"] = MustNewMethod(......
Open Graph Description: Simple description I cannot find a way to access globals() within a bounded method in GoLang. I expose a type into module, like moduleImpl.Globals["Foo"] = FooType, and add methods to FooType by Fo...
X Description: Simple description I cannot find a way to access globals() within a bounded method in GoLang. I expose a type into module, like moduleImpl.Globals["Foo"] = FooType, and add methods to Foo...
Opengraph URL: https://github.com/go-python/gpython/issues/211
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"How to get `globals()` inside Go bounded method?","articleBody":"## Simple description\r\n\r\nI cannot find a way to access `globals()` within a bounded method in GoLang.\r\n\r\nI expose a type into module, like `moduleImpl.Globals[\"Foo\"] = FooType`, and add methods to FooType by `FooType.Globals[\"bar\"] = MustNewMethod(..., someGoMethod, ...)`. \r\n\r\nI cannot access module's global variables inside `someGoMethod`.\r\n\r\n## Why I need this feature\r\n\r\nI just attach different `zap.Logger` to multiple `py.Context`s. I attach `logger` as a module's global variable, by using\r\n\r\n```\r\nctx.GetModule(\"name\").Globals[\"logger\"] = \u0026pyLoggerObject{logger}\r\n```\r\n\r\nbut I cannot find a way to use this logger inside bounded methods.\r\n\r\n\r\n---\r\n\r\nI found I can create a py.Type and attach the type to module global dynamically. I can somehow read module globals by this trick. But Is there a elegant way to archive that?\r\n\r\n```\r\nm = ctx.GetModule(\"module\")\r\nm.Globals[\"Foo\"] = NewFooType(m)\r\n```","author":{"url":"https://github.com/reyoung","@type":"Person","name":"reyoung"},"datePublished":"2022-12-13T08:03:17.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/211/gpython/issues/211"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:be0fdf96-8680-a68e-a7b3-19729c6efa6b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 86B8:2445E2:11B3389:1737505:696D4C1E |
| html-safe-nonce | 86ba327c197136796de8b4492efb55710a312d42dba8a1c5088ba43170738161 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NkI4OjI0NDVFMjoxMUIzMzg5OjE3Mzc1MDU6Njk2RDRDMUUiLCJ2aXNpdG9yX2lkIjoiOTAyMTQ5NTY5NTEwNDYyNTY5NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | e6825866bf3a57b0d680e6bbef3698afbbb764b1d0975e3b94fb674f4fb758a5 |
| hovercard-subject-tag | issue:1493648286 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/go-python/gpython/211/issue_layout |
| twitter:image | https://opengraph.githubassets.com/75950f50f53836d9c9d7440372be9e03cc12c1dcfad9cf6bea804116988f2245/go-python/gpython/issues/211 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/75950f50f53836d9c9d7440372be9e03cc12c1dcfad9cf6bea804116988f2245/go-python/gpython/issues/211 |
| og:image:alt | Simple description I cannot find a way to access globals() within a bounded method in GoLang. I expose a type into module, like moduleImpl.Globals["Foo"] = FooType, and add methods to FooType by Fo... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | reyoung |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0944e430045f4fb5f7bd103e0660080acfe593174063212555773ca41c144a14 |
| turbo-cache-control | no-preview |
| go-import | github.com/go-python/gpython git https://github.com/go-python/gpython.git |
| octolytics-dimension-user_id | 7604679 |
| octolytics-dimension-user_login | go-python |
| octolytics-dimension-repository_id | 143203535 |
| octolytics-dimension-repository_nwo | go-python/gpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 143203535 |
| octolytics-dimension-repository_network_root_nwo | go-python/gpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 66b6e773801d28660016072069017cfcc851f54b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width