Title: gcurve/gdots constructor ignores size= (writes a dead _size; the derived property reports the default) · Issue #287 · vpython/vpython-jupyter · GitHub
Open Graph Title: gcurve/gdots constructor ignores size= (writes a dead _size; the derived property reports the default) · Issue #287 · vpython/vpython-jupyter
X Title: gcurve/gdots constructor ignores size= (writes a dead _size; the derived property reports the default) · Issue #287 · vpython/vpython-jupyter
Description: gcurve(size=…) / gdots(size=…) is silently ignored: the constructed object keeps the default radius and the browser is sent the default size of 6, whatever the caller asked for. Setting .size after construction works, and so does radius=...
Open Graph Description: gcurve(size=…) / gdots(size=…) is silently ignored: the constructed object keeps the default radius and the browser is sent the default size of 6, whatever the caller asked for. Setting .size after...
X Description: gcurve(size=…) / gdots(size=…) is silently ignored: the constructed object keeps the default radius and the browser is sent the default size of 6, whatever the caller asked for. Setting .size after...
Opengraph URL: https://github.com/vpython/vpython-jupyter/issues/287
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"gcurve/gdots constructor ignores size= (writes a dead _size; the derived property reports the default)","articleBody":"`gcurve(size=…)` / `gdots(size=…)` is silently ignored: the constructed object keeps the default radius and the browser is sent the default `size` of 6, whatever the caller asked for. Setting `.size` **after** construction works, and so does `radius=` in the constructor — only the constructor's `size=` is lost.\n\n```python\nfrom vpython import *\ng = graph()\nd = gdots(graph=g, size=8, color=color.blue)\nprint(d.size) # 6 — expected 8\nd.size = 8\nprint(d.size) # 8 — the setter is fine\n```\n\n### Cause\n\n`gobj.size` is a *derived* property backed by `_radius` (`vpython/vpython.py:2207-2212`):\n\n```python\n@property\ndef size(self): return 2*self._radius\n@size.setter\ndef size(self, val):\n self._radius = val/2\n self.addattr('radius')\n```\n\nBut `gobj.setup`'s scalar-argument loop (`vpython/vpython.py:2168-2174`) writes the private name directly, bypassing the property:\n\n```python\nfor a, val in args.items():\n argsToSend.append(a)\n if a == 'graph':\n val = val.idx\n setattr(self, '_' + a, val) # size=8 -> self._size = 8\n```\n\n`self._size` is a dead attribute — nothing in the package reads it. The send loop immediately below then reads back through the property:\n\n```python\nfor a in argsToSend:\n ...\n aval = getattr(self, a) # getattr(self,'size') -> 2*self._radius -> 6\n cmd[a] = aval\n```\n\nso `size: 6` goes on the wire and `_size` is never consulted again. Minimal demonstration:\n\n```python\nclass Fake:\n def __init__(self): self._radius = 3\n @property\n def size(self): return 2*self._radius\n @size.setter\n def size(self, val): self._radius = val/2\n\no = Fake()\nsetattr(o, '_size', 8) # what gobj.setup does\no._size # 8 (dead)\ngetattr(o, 'size') # 6 \u003c-- what is sent\n```\n\n`radius=8` works for the same reason in reverse: `_radius` *is* the real backing attribute, so `setattr(self, '_radius', 8)` lands in the right slot and `getattr(self, 'radius')` reads it back.\n\n### Scope\n\nI swept every `@property` in the `gobj` class body (lines 2122-2338) for getters that are not simply `return self._\u003cname>`. **`size` is the only one**, so this looks like a single-attribute bug rather than a pattern — but the *mechanism* (`setattr(self, '_' + a, val)` against a derived property) would bite any future attribute defined the same way, which is the part worth guarding.\n\nNot verified beyond `gobj`: other classes have their own `setup` methods with the same `setattr(self, '_' + a, val)` idiom and their own derived `size`/`axis` properties (e.g. `vpython.py:815`, `:1205`, `:1322`, `:1623`), where size and axis interact. Those may be fine — the interaction is handled explicitly there — but they are the same shape.\n\n### Suggested fix\n\nIn `gobj.setup`'s scalar loop, route through the property when one exists, or special-case the derived name:\n\n```python\nfor a, val in args.items():\n argsToSend.append(a)\n if a == 'graph':\n val = val.idx\n if a == 'size': # derived: backed by _radius, not _size\n self._radius = val/2\n else:\n setattr(self, '_' + a, val)\n```\n\nSetting `_radius` directly rather than calling the public setter is deliberate: the `size` setter also calls `addattr('radius')`, and `addattr` spins on `baseObj.sent` (`vpython.py:305-308`). During construction that is at best redundant — the value is already going out in this constructor's own `cmd` — and on a single-threaded host (Pyodide/wasm) a spin-wait inside a constructor is a deadlock rather than a delay.\n\nHappy to open a PR. Two questions if you have a preference:\n\n1. Special-case `size`, or make the loop property-aware in general (`if isinstance(getattr(type(self), a, None), property)`)? The general form guards the mechanism; the special case is smaller and cannot surprise anything else.\n2. Should the other `setup` implementations with derived `size`/`axis` get the same audit in the same change, or separately?\n\n### How it surfaced\n\nFound while adopting this package to run Web VPython under Pyodide in a Web Worker for [trinket](https://github.com/PICUP-Physics/trinket-oss). Trinket's existing bridge bypasses `gobj.setup` entirely (it forwards constructor kwargs straight to the GlowScript object), so `gdots(size=8)` works there today and stops working when the real package is used — which is how a long-standing bug turned up as an apparent regression. Nothing about the worker or the transport is involved; the wire package carries `size: 6` on the notebook path too.\n","author":{"url":"https://github.com/sspickle","@type":"Person","name":"sspickle"},"datePublished":"2026-08-10T21:59:46Z","url":"https://github.com/vpython/vpython-jupyter/issues/287"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:5634d934-0896-eef0-b644-e62a59ce5a40 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E3BC:2E2180:61FC:8615:6B007D05 |
| html-safe-nonce | 523d50a05c54c7295892aa4ccbb95dcb235dae604a444af334e42be6bc5a4c0c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFM0JDOjJFMjE4MDo2MUZDOjg2MTU6NkIwMDdEMDUiLCJ2aXNpdG9yX2lkIjoiNjk0NDk1NDUzNDUxNDk0OTM4MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a053428c6618b5bbd9de8823f0917694f964a277a7b31332b2fd6bb93b8665ab |
| hovercard-subject-tag | issue:5114708751 |
| 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/vpython/vpython-jupyter/287/issue_layout |
| twitter:image | https://opengraph.githubassets.com/cb4bc5ddb5bf8be5f83debd0202b1b6426e57e897f1ac077410bf6916a206fb3/vpython/vpython-jupyter/issues/287 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/cb4bc5ddb5bf8be5f83debd0202b1b6426e57e897f1ac077410bf6916a206fb3/vpython/vpython-jupyter/issues/287 |
| og:image:alt | gcurve(size=…) / gdots(size=…) is silently ignored: the constructed object keeps the default radius and the browser is sent the default size of 6, whatever the caller asked for. Setting .size after... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sspickle |
| hostname | github.com |
| expected-hostname | github.com |
| None | 82c186f13e104004ab7bdb779f3195e59dd38bfde531aaa74b76470fc2462b83 |
| turbo-cache-control | no-preview |
| go-import | github.com/vpython/vpython-jupyter git https://github.com/vpython/vpython-jupyter.git |
| octolytics-dimension-user_id | 1280757 |
| octolytics-dimension-user_login | vpython |
| octolytics-dimension-repository_id | 187905226 |
| octolytics-dimension-repository_nwo | vpython/vpython-jupyter |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 187905226 |
| octolytics-dimension-repository_network_root_nwo | vpython/vpython-jupyter |
| 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 | d1bc2aa1939001689f5ce935982c10a6138f745c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width