Title: Side effect of FrozenJSON.__getattr__ not raising KeyError · Issue #46 · fluentpython/example-code-2e · GitHub
Open Graph Title: Side effect of FrozenJSON.__getattr__ not raising KeyError · Issue #46 · fluentpython/example-code-2e
X Title: Side effect of FrozenJSON.__getattr__ not raising KeyError · Issue #46 · fluentpython/example-code-2e
Description: Hi Luciano, In chapter 22 you mention that FrozenJSON.__getattr__() raising a KeyError is "not to confusing". However, today I discovered a side effect from this that is confusing: copy.copy(FrozenJSON({'name': 'Jim Bo', 'class': 1982}))...
Open Graph Description: Hi Luciano, In chapter 22 you mention that FrozenJSON.__getattr__() raising a KeyError is "not to confusing". However, today I discovered a side effect from this that is confusing: copy.copy(Frozen...
X Description: Hi Luciano, In chapter 22 you mention that FrozenJSON.__getattr__() raising a KeyError is "not to confusing". However, today I discovered a side effect from this that is confusing: copy.c...
Opengraph URL: https://github.com/fluentpython/example-code-2e/issues/46
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Side effect of FrozenJSON.__getattr__ not raising KeyError","articleBody":"Hi Luciano, \r\n\r\nIn chapter 22 you mention that `FrozenJSON.__getattr__()` raising a `KeyError` is \"not to confusing\". However, today I discovered a side effect from this that __is__ confusing: `copy.copy(FrozenJSON({'name': 'Jim Bo', 'class': 1982}))` raises a `RecursionError`.\r\n\r\nIndeed the documentation states that an `AttributeError` should be raised (https://docs.python.org/3/reference/datamodel.html#object.__getattr__) and apparently this is relied upon in the stdlib. In the copy implementation a new instance of `FrozenJSON` is generated without the initializer being called. Then, when looking for some optional dunder methods (that are not found) the copy implementation triggers a `__getattr__` call with `self.__data` not yet existing, triggering the recursion.\r\n\r\nWhat I appreciate in your book is that you are always very precise about all types of unexpected side effects, so maybe you could consider spending some text on this in a future update. \r\n\r\nBest regards, Michiel","author":{"url":"https://github.com/hayemj","@type":"Person","name":"hayemj"},"datePublished":"2024-07-17T20:12:49.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/46/example-code-2e/issues/46"}
| 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:8296b4e5-f692-15b1-3951-46be5b0439fe |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8174:3DAFE8:41DDA8B:59867E9:6970952F |
| html-safe-nonce | 9fef247f97f312252cfc2c986070c40f35a56ceffe8576c1020aff5ad8d8dc8f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MTc0OjNEQUZFODo0MUREQThCOjU5ODY3RTk6Njk3MDk1MkYiLCJ2aXNpdG9yX2lkIjoiNTcyNjU3NzIzNzQwNTU4NjM5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 878bc90115df70ba8f5a45a07d6a5d9cf13fb5080cc60fbbeb477ea82a9b0025 |
| hovercard-subject-tag | issue:2414478447 |
| 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/fluentpython/example-code-2e/46/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b6fabb3e6cc08d7170e9b933dbd7a093848014e6d79e03a77bb8a90ece3749f8/fluentpython/example-code-2e/issues/46 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b6fabb3e6cc08d7170e9b933dbd7a093848014e6d79e03a77bb8a90ece3749f8/fluentpython/example-code-2e/issues/46 |
| og:image:alt | Hi Luciano, In chapter 22 you mention that FrozenJSON.__getattr__() raising a KeyError is "not to confusing". However, today I discovered a side effect from this that is confusing: copy.copy(Frozen... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | hayemj |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9920a62ba22d06470388e2904804fb7e5ec51c9e35f81784e9191394c74b2bd2 |
| turbo-cache-control | no-preview |
| go-import | github.com/fluentpython/example-code-2e git https://github.com/fluentpython/example-code-2e.git |
| octolytics-dimension-user_id | 9216311 |
| octolytics-dimension-user_login | fluentpython |
| octolytics-dimension-repository_id | 176997413 |
| octolytics-dimension-repository_nwo | fluentpython/example-code-2e |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 176997413 |
| octolytics-dimension-repository_network_root_nwo | fluentpython/example-code-2e |
| 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 | 7d6181066430cc06553c8396ca201e194ae33cb9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width