Title: Incorrect fetch from the OD objects due to their `__len__` method · Issue #588 · canopen-python/canopen · GitHub
Open Graph Title: Incorrect fetch from the OD objects due to their `__len__` method · Issue #588 · canopen-python/canopen
X Title: Incorrect fetch from the OD objects due to their `__len__` method · Issue #588 · canopen-python/canopen
Description: As I was looking at #436 I did some tracing and noticed that ODVariable.__len__ is called many more times than expected and I uncovered a side effect: In ObjectDictionary.__getitem__() we have in L136 the line item = self.names.get(index...
Open Graph Description: As I was looking at #436 I did some tracing and noticed that ODVariable.__len__ is called many more times than expected and I uncovered a side effect: In ObjectDictionary.__getitem__() we have in L...
X Description: As I was looking at #436 I did some tracing and noticed that ODVariable.__len__ is called many more times than expected and I uncovered a side effect: In ObjectDictionary.__getitem__() we have in L...
Opengraph URL: https://github.com/canopen-python/canopen/issues/588
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Incorrect fetch from the OD objects due to their `__len__` method","articleBody":"As I was looking at #436 I did some tracing and noticed that `ODVariable.__len__` is called many more times than expected and I uncovered a side effect:\n\nIn `ObjectDictionary.__getitem__()` we have in L136 the line `item = self.names.get(index) or self.indices.get(index)`. What happens here is that python looks up the index from `self.names` first. When it has found an object, it evaluates if this object is false, and it does so by running its `__len__()` function. That it will call `ODVariable.__len__`, `ODArray.__len__` or `ODRecord.__len__`. If this happens to be 0, the object fails the test it moves on to the next step, potentially returning `None`.\n\nReference: https://docs.python.org/3/library/stdtypes.html#truth-value-testing\n\nI assume we might be interested in fixing this?\n\nhttps://github.com/canopen-python/canopen/blob/7ddb19b2ca7b7a85b9cef3090249b00293dd4b4a/canopen/objectdictionary/__init__.py#L132-L142\n","author":{"url":"https://github.com/sveinse","@type":"Person","name":"sveinse"},"datePublished":"2025-06-14T22:07:18.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/588/canopen/issues/588"}
| 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:3f26b58b-f13f-5f62-0605-52e35b9770f1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 98F0:1FBD82:466A156:5D21D47:6A5D7712 |
| html-safe-nonce | 97296d0d0cc27723b658224377453c4df5aff42c5bced716a9badbb6d367792a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5OEYwOjFGQkQ4Mjo0NjZBMTU2OjVEMjFENDc6NkE1RDc3MTIiLCJ2aXNpdG9yX2lkIjoiMTUwMTQ1MjQzNzM5OTg5Mzc3OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 7cd6a07bcfe45984041617e217656a1fb202c552e6d92fb1297771f477e1c798 |
| hovercard-subject-tag | issue:3146826630 |
| 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/canopen-python/canopen/588/issue_layout |
| twitter:image | https://opengraph.githubassets.com/dc1a512771570f1880fdd44d81d64b79c2f453723c75d945573ab179fb7ec44e/canopen-python/canopen/issues/588 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/dc1a512771570f1880fdd44d81d64b79c2f453723c75d945573ab179fb7ec44e/canopen-python/canopen/issues/588 |
| og:image:alt | As I was looking at #436 I did some tracing and noticed that ODVariable.__len__ is called many more times than expected and I uncovered a side effect: In ObjectDictionary.__getitem__() we have in L... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sveinse |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| turbo-cache-control | no-preview |
| go-import | github.com/canopen-python/canopen git https://github.com/canopen-python/canopen.git |
| octolytics-dimension-user_id | 200581454 |
| octolytics-dimension-user_login | canopen-python |
| octolytics-dimension-repository_id | 68737600 |
| octolytics-dimension-repository_nwo | canopen-python/canopen |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 68737600 |
| octolytics-dimension-repository_network_root_nwo | canopen-python/canopen |
| 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 | 9c975978430e9ad293956f2bbdaf153b1bd84a99 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width