Title: Problem with make function on page 843 · Issue #47 · fluentpython/example-code-2e · GitHub
Open Graph Title: Problem with make function on page 843 · Issue #47 · fluentpython/example-code-2e
X Title: Problem with make function on page 843 · Issue #47 · fluentpython/example-code-2e
Description: I believe the pseudocode for object construction on page 843 is somewhat misleading: def make(the_class, some_arg): new_object = the_class.__new__(some_arg) if isinstance(new_object, the_class): the_class.__init__(new_object, some_arg) r...
Open Graph Description: I believe the pseudocode for object construction on page 843 is somewhat misleading: def make(the_class, some_arg): new_object = the_class.__new__(some_arg) if isinstance(new_object, the_class): th...
X Description: I believe the pseudocode for object construction on page 843 is somewhat misleading: def make(the_class, some_arg): new_object = the_class.__new__(some_arg) if isinstance(new_object, the_class): th...
Opengraph URL: https://github.com/fluentpython/example-code-2e/issues/47
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Problem with make function on page 843","articleBody":"I believe the pseudocode for object construction on page 843 is somewhat misleading:\r\n\r\n```python\r\ndef make(the_class, some_arg):\r\n new_object = the_class.__new__(some_arg)\r\n if isinstance(new_object, the_class):\r\n the_class.__init__(new_object, some_arg)\r\n return new_object\r\n```\r\n\r\nFirstly, it doesn't function correctly even in the simplest case. `the_class.__new__(some_arg)` should be called as `the_class.__new__(the_class, some_arg)` for proper operation. Secondly, it lacks generality. I suggest the following code as a more suitable replacement:\r\n\r\n```python\r\ndef make(the_class, *args, **kwargs):\r\n new_object = the_class.__new__(the_class, *args, **kwargs)\r\n if isinstance(new_object, the_class):\r\n the_class.__init__(new_object, *args, **kwargs)\r\n return new_object\r\n```","author":{"url":"https://github.com/kamalfarahani","@type":"Person","name":"kamalfarahani"},"datePublished":"2024-10-30T12:22:09.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/47/example-code-2e/issues/47"}
| 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:3d0f069b-6356-56a6-fbe0-e9008826b12b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BE46:10C46F:12F3D40:1A7D904:6972680F |
| html-safe-nonce | d767de9fe2e0fa1eeda38903480d560b57f165451eff298a62d40feac026e984 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRTQ2OjEwQzQ2RjoxMkYzRDQwOjFBN0Q5MDQ6Njk3MjY4MEYiLCJ2aXNpdG9yX2lkIjoiNjgxOTY0NjAwNzQ3NDgwODg0OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d21631d456538dbbfc0ecdbdba042cd03f1f06fcb1e611934742a199a28fb059 |
| hovercard-subject-tag | issue:2623930491 |
| 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/47/issue_layout |
| twitter:image | https://opengraph.githubassets.com/19c012931820b3010eff728dcb84cc8b3105f824adc5728681dcb4cfdc8268ba/fluentpython/example-code-2e/issues/47 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/19c012931820b3010eff728dcb84cc8b3105f824adc5728681dcb4cfdc8268ba/fluentpython/example-code-2e/issues/47 |
| og:image:alt | I believe the pseudocode for object construction on page 843 is somewhat misleading: def make(the_class, some_arg): new_object = the_class.__new__(some_arg) if isinstance(new_object, the_class): th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | kamalfarahani |
| hostname | github.com |
| expected-hostname | github.com |
| None | ab2c8e6ec49d8737f6bf007a86b2c4a2bc434bba562c524e0c76465bc9ed358b |
| 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 | 76f982acc7b406671507aee04f00d64414a22dbf |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width