Title: Problematic behavior of `locals()` inside a funtion · Issue #368 · datajoint/datajoint-python · GitHub
Open Graph Title: Problematic behavior of `locals()` inside a funtion · Issue #368 · datajoint/datajoint-python
X Title: Problematic behavior of `locals()` inside a funtion · Issue #368 · datajoint/datajoint-python
Description: Use of locals() inside a function leads to unexpected behavior. For an example, the following code snippet def make_tables(): schema = dj.schema('test', locals()) @schema class A(): definition = """ id: int # id """ @schema class B(): de...
Open Graph Description: Use of locals() inside a function leads to unexpected behavior. For an example, the following code snippet def make_tables(): schema = dj.schema('test', locals()) @schema class A(): definition = ""...
X Description: Use of locals() inside a function leads to unexpected behavior. For an example, the following code snippet def make_tables(): schema = dj.schema('test', locals()) @schema class A(): definit...
Opengraph URL: https://github.com/datajoint/datajoint-python/issues/368
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Problematic behavior of `locals()` inside a funtion","articleBody":"Use of `locals()` inside a function leads to unexpected behavior. For an example, the following code snippet\r\n\r\n```python\r\ndef make_tables():\r\n schema = dj.schema('test', locals())\r\n \r\n @schema\r\n class A():\r\n definition = \"\"\"\r\n id: int # id\r\n \"\"\"\r\n @schema\r\n class B():\r\n definition = \"\"\"\r\n -\u003e A\r\n \"\"\"\r\n```\r\nCalling the fucntion `make_tables()` will result in name resolution error for the foreign key reference `-\u003e A` inside the definition of `B` despite the fact that the following works just fine:\r\n\r\n```python\r\nschema = dj.schema('test', locals())\r\n \r\n@schema\r\nclass A():\r\n definition = \"\"\"\r\n id: int # id\r\n \"\"\"\r\n@schema\r\nclass B():\r\n definition = \"\"\"\r\n -\u003e A\r\n \"\"\"\r\n```\r\n\r\nThe problem arise due to the fact that, for some reasons, the dictionary returned by the `locals()` do *not* stay updated when used inside a function. This can be demonstrated by the following code:\r\n\r\n```python\r\ndef test_locals():\r\n names = locals()\r\n print(names.keys()) # will print out []\r\n # add new variables\r\n a = 10\r\n b = 5 \r\n print(names.keys()) # still print out []!\r\n print(locals().keys()) # ['names', 'a', 'b']\r\n print(names.keys()) # ['names', 'a', 'b']\r\n```\r\n\r\nThis makes the use of `locals()` highly unreliable inside a function.","author":{"url":"https://github.com/eywalker","@type":"Person","name":"eywalker"},"datePublished":"2017-10-04T06:52:44.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/368/datajoint-python/issues/368"}
| 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:7011e1bb-4ec9-d208-bc6b-465660c281cc |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C35A:490E8:1564ED7:1DAC005:6A4DEF71 |
| html-safe-nonce | 5013219e782a3f0c12ea6312c50694151956065675fbd147df0166f2646d029a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMzVBOjQ5MEU4OjE1NjRFRDc6MURBQzAwNTo2QTRERUY3MSIsInZpc2l0b3JfaWQiOiI3NjQ1NTM5NzIwMjczNTQ5OTMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d90d9902f941a75f390ceb157fd5080bd82935c83f44ac8142b5f63944cf1b22 |
| hovercard-subject-tag | issue:262684397 |
| 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/datajoint/datajoint-python/368/issue_layout |
| twitter:image | https://opengraph.githubassets.com/25b5e3a99c42501f55d82ba373c3b953ac7aa9a506802511b8fe699711e18435/datajoint/datajoint-python/issues/368 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/25b5e3a99c42501f55d82ba373c3b953ac7aa9a506802511b8fe699711e18435/datajoint/datajoint-python/issues/368 |
| og:image:alt | Use of locals() inside a function leads to unexpected behavior. For an example, the following code snippet def make_tables(): schema = dj.schema('test', locals()) @schema class A(): definition = ""... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | eywalker |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5818716c93c6a2925b815402541a32814e43a7b1261c322b0c2df75224289566 |
| turbo-cache-control | no-preview |
| go-import | github.com/datajoint/datajoint-python git https://github.com/datajoint/datajoint-python.git |
| octolytics-dimension-user_id | 2375501 |
| octolytics-dimension-user_login | datajoint |
| octolytics-dimension-repository_id | 5866704 |
| octolytics-dimension-repository_nwo | datajoint/datajoint-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 5866704 |
| octolytics-dimension-repository_network_root_nwo | datajoint/datajoint-python |
| 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 | f4bb89367ca678f057d79b1abc45d6675b1bd5b2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width