Title: Potential Issue with moduleCache Key Handling in _utils.py · Issue #585 · html5lib/html5lib-python · GitHub
Open Graph Title: Potential Issue with moduleCache Key Handling in _utils.py · Issue #585 · html5lib/html5lib-python
X Title: Potential Issue with moduleCache Key Handling in _utils.py · Issue #585 · html5lib/html5lib-python
Description: While reviewing the moduleCache handling logic in _utils.py, I noticed a potential inconsistency in how keys are being checked and used. Specifically, the code appears to check for the presence of "kwargs", "name", and "args" as string k...
Open Graph Description: While reviewing the moduleCache handling logic in _utils.py, I noticed a potential inconsistency in how keys are being checked and used. Specifically, the code appears to check for the presence of ...
X Description: While reviewing the moduleCache handling logic in _utils.py, I noticed a potential inconsistency in how keys are being checked and used. Specifically, the code appears to check for the presence of ...
Opengraph URL: https://github.com/html5lib/html5lib-python/issues/585
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":" Potential Issue with moduleCache Key Handling in _utils.py","articleBody":"\r\nWhile reviewing the moduleCache handling logic in _utils.py, I noticed a potential inconsistency in how keys are being checked and used. Specifically, the code appears to check for the presence of \"kwargs\", \"name\", and \"args\" as string keys in the moduleCache dictionary. However, it seems the variables themselves (e.g., kwargs, name, args) are being used elsewhere as keys.\r\n\r\nFor example, in the code snippet:\r\n```python\r\nif \"name\" not in moduleCache:\r\n moduleCache[name] = {}\r\nif \"args\" not in moduleCache[name]:\r\n moduleCache[name][args] = {}\r\nif \"kwargs\" not in moduleCache[name][args]:\r\n moduleCache[name][args][kwargs_tuple] = {}\r\nmoduleCache[name][args][kwargs_tuple] = mod\r\n```\r\nThe checks for \"name\", \"args\", and \"kwargs\" are strings, but the subsequent access and assignment use the variables name, args, and kwargs_tuple as keys.\r\n\r\nPotential Issues\r\n\r\n\t1.\tKey Mismatch: If the intention was to check the presence of the variables name, args, and kwargs_tuple as keys, using string literals like \"name\" might lead to incorrect behavior.\r\n\t2.\tRedundant Checks: If these strings (\"name\", \"args\", \"kwargs\") are unrelated to the actual variables name, args, and kwargs_tuple, this could result in redundant checks or unexpected behavior.\r\n\r\nSteps to Reproduce\r\n\r\n\t1.\tUse the relevant code path that triggers the moduleCache logic.\r\n\t2.\tPopulate the moduleCache with keys that demonstrate the mismatch (e.g., strings like \"name\" vs. variable name).\r\n\r\nExpected Behavior\r\n\r\nThe moduleCache should consistently use either string literals or variables as keys.\r\n\r\nProposed Solution\r\n\r\n\t1.\tIf the intention is to use the variables name, args, and kwargs_tuple as keys, update the conditional checks to remove string literals:\r\n```python\r\nif name not in moduleCache:\r\n moduleCache[name] = {}\r\nif args not in moduleCache[name]:\r\n moduleCache[name][args] = {}\r\nif kwargs_tuple not in moduleCache[name][args]:\r\n moduleCache[name][args][kwargs_tuple] = {}\r\n```\r\n\r\n\t2.\tIf the current logic with string literals is correct, clarify the relationship between the string keys and the variable keys to avoid confusion.\r\n\r\nThis potential issue might lead to unexpected results, especially in edge cases where the string and variable keys overlap or differ.\r\n","author":{"url":"https://github.com/thisisandy","@type":"Person","name":"thisisandy"},"datePublished":"2024-12-10T21:49:25.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/585/html5lib-python/issues/585"}
| 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:c2c70021-9ee5-1575-1d01-100787bf9e05 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8626:3020B7:E2CD3D:135E828:696E8E16 |
| html-safe-nonce | cff046a1b0c2523f1205d796a3c079e039cc54186dc45e863c795373f93a4272 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NjI2OjMwMjBCNzpFMkNEM0Q6MTM1RTgyODo2OTZFOEUxNiIsInZpc2l0b3JfaWQiOiI2NTY0MTgxNzg2NTAwMTczMzM0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | aa55de21b6c75f93c2e899bd6855dd8ae7e372ba87c0752ac93daafe2c0202ea |
| hovercard-subject-tag | issue:2731263716 |
| 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/html5lib/html5lib-python/585/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b7aef882fe11b5a155dda21aca8cca34ce4aedf8cd0eda13a242de8ec5c86236/html5lib/html5lib-python/issues/585 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b7aef882fe11b5a155dda21aca8cca34ce4aedf8cd0eda13a242de8ec5c86236/html5lib/html5lib-python/issues/585 |
| og:image:alt | While reviewing the moduleCache handling logic in _utils.py, I noticed a potential inconsistency in how keys are being checked and used. Specifically, the code appears to check for the presence of ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | thisisandy |
| hostname | github.com |
| expected-hostname | github.com |
| None | fdad15fd2ad43212aa8b8be5f2c2725550f8374ceeeb154a999ad9145b43f3f7 |
| turbo-cache-control | no-preview |
| go-import | github.com/html5lib/html5lib-python git https://github.com/html5lib/html5lib-python.git |
| octolytics-dimension-user_id | 4092973 |
| octolytics-dimension-user_login | html5lib |
| octolytics-dimension-repository_id | 9322649 |
| octolytics-dimension-repository_nwo | html5lib/html5lib-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 9322649 |
| octolytics-dimension-repository_network_root_nwo | html5lib/html5lib-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 | 27b23bc056eb973d350fc95afc848757edb9e7a9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width