Title: Version 0.16.2: error when parsing unit strings with spaces · Issue #259 · python-quantities/python-quantities · GitHub
Open Graph Title: Version 0.16.2: error when parsing unit strings with spaces · Issue #259 · python-quantities/python-quantities
X Title: Version 0.16.2: error when parsing unit strings with spaces · Issue #259 · python-quantities/python-quantities
Description: Thank you for all your work creating this library! In previous versions, you could parse a units string in the format " m" (with a leading space). Python 3.12.8 (main, Dec 6 2024, 00:00:00) [GCC 14.2.1 20240912 (Red Hat 14.2.1-3)] on lin...
Open Graph Description: Thank you for all your work creating this library! In previous versions, you could parse a units string in the format " m" (with a leading space). Python 3.12.8 (main, Dec 6 2024, 00:00:00) [GCC 14...
X Description: Thank you for all your work creating this library! In previous versions, you could parse a units string in the format " m" (with a leading space). Python 3.12.8 (main, Dec 6 2024, 00:00:0...
Opengraph URL: https://github.com/python-quantities/python-quantities/issues/259
X: @github
Domain: www.github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Version 0.16.2: error when parsing unit strings with spaces","articleBody":"Thank you for all your work creating this library!\n\nIn previous versions, you could parse a units string in the format `\" m\"` (with a leading space). \n```\nPython 3.12.8 (main, Dec 6 2024, 00:00:00) [GCC 14.2.1 20240912 (Red Hat 14.2.1-3)] on linux\n\u003e\u003e\u003e import quantities\n\u003e\u003e\u003e quantities.__version__\n'0.16.1'\n\u003e\u003e\u003e quantities.quantity.validate_dimensionality(\" m\")\nDimensionality({meter: 1})\n```\n\nhowever, the newer version's switch to using `ast.parse` instead of `eval` causes errors in this case:\n```\nPython 3.12.8 (main, Dec 6 2024, 00:00:00) [GCC 14.2.1 20240912 (Red Hat 14.2.1-3)] on linux\n\u003e\u003e\u003e import quantities\n\u003e\u003e\u003e quantities.__version__\n'0.16.2'\n\u003e\u003e\u003e quantities.quantity.validate_dimensionality(\" m\")\nTraceback (most recent call last):\n File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\n File \"/home/jbonilla/.local/lib/python3.12/site-packages/quantities/quantity.py\", line 34, in validate_dimensionality\n return unit_registry[value].dimensionality\n ~~~~~~~~~~~~~^^^^^^^\n File \"/home/jbonilla/.local/lib/python3.12/site-packages/quantities/registry.py\", line 82, in __getitem__\n return self.__registry[label]\n ~~~~~~~~~~~~~~~^^^^^^^\n File \"/home/jbonilla/.local/lib/python3.12/site-packages/quantities/registry.py\", line 32, in __getitem__\n tree = ast.parse(string, mode=\"eval\")\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/usr/lib64/python3.12/ast.py\", line 52, in parse\n return compile(source, filename, mode, flags,\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"\u003cunknown\u003e\", line 1\n m\nIndentationError: unexpected indent\n```\n\nNot sure if supporting whitespace around the units was ever intended, but this change caused some issues on our codebase that depended on this behavior. This is also probably related to #256 .","author":{"url":"https://github.com/juan-g-bonilla","@type":"Person","name":"juan-g-bonilla"},"datePublished":"2025-07-02T16:48:51.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/259/python-quantities/issues/259"}
| 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:143c9d59-1e91-dede-41c3-6118f7d613b0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | ED1A:39E51F:FDC3B8:14A44D5:696B0C49 |
| html-safe-nonce | 765af2d5a3b395ce5f8e6cc86c4dfd9af78ee17fac103e01642d767cbca3c755 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFRDFBOjM5RTUxRjpGREMzQjg6MTRBNDRENTo2OTZCMEM0OSIsInZpc2l0b3JfaWQiOiI1MTk0NzkyNzg3NzEzMzk1Nzg2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 8266f222ee70e6820d4cb762b937fa3a4ecb5c8c42b8121f504a55e01646176d |
| hovercard-subject-tag | issue:3196545741 |
| 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/python-quantities/python-quantities/259/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b0a0dc50a967ddb8e54ef97763f4be8daf1236cc4a9fe2115926a1a73e8d0146/python-quantities/python-quantities/issues/259 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b0a0dc50a967ddb8e54ef97763f4be8daf1236cc4a9fe2115926a1a73e8d0146/python-quantities/python-quantities/issues/259 |
| og:image:alt | Thank you for all your work creating this library! In previous versions, you could parse a units string in the format " m" (with a leading space). Python 3.12.8 (main, Dec 6 2024, 00:00:00) [GCC 14... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | juan-g-bonilla |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| turbo-cache-control | no-preview |
| go-import | github.com/python-quantities/python-quantities git https://github.com/python-quantities/python-quantities.git |
| octolytics-dimension-user_id | 222003 |
| octolytics-dimension-user_login | python-quantities |
| octolytics-dimension-repository_id | 560911 |
| octolytics-dimension-repository_nwo | python-quantities/python-quantities |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 560911 |
| octolytics-dimension-repository_network_root_nwo | python-quantities/python-quantities |
| 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 | 82560a55c6b2054555076f46e683151ee28a19bc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width