Title: The code `checked_demo.py` in Chapter 24 has TypeError: 'title' type hint must be callable? · Issue #30 · fluentpython/example-code-2e · GitHub
Open Graph Title: The code `checked_demo.py` in Chapter 24 has TypeError: 'title' type hint must be callable? · Issue #30 · fluentpython/example-code-2e
X Title: The code `checked_demo.py` in Chapter 24 has TypeError: 'title' type hint must be callable? · Issue #30 · fluentpython/example-code-2e
Description: Hello, I run the code in https://github.com/fluentpython/example-code-2e/tree/master/24-class-metaprog/checked/metaclass/checked_demo.py #!/usr/bin/env python3 # tag::MOVIE_DEMO[] from checkedlib import Checked class Movie(Checked): titl...
Open Graph Description: Hello, I run the code in https://github.com/fluentpython/example-code-2e/tree/master/24-class-metaprog/checked/metaclass/checked_demo.py #!/usr/bin/env python3 # tag::MOVIE_DEMO[] from checkedlib i...
X Description: Hello, I run the code in https://github.com/fluentpython/example-code-2e/tree/master/24-class-metaprog/checked/metaclass/checked_demo.py #!/usr/bin/env python3 # tag::MOVIE_DEMO[] from checkedlib i...
Opengraph URL: https://github.com/fluentpython/example-code-2e/issues/30
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"The code `checked_demo.py` in Chapter 24 has TypeError: 'title' type hint must be callable?","articleBody":"Hello,\r\n\r\nI run the code in https://github.com/fluentpython/example-code-2e/tree/master/24-class-metaprog/checked/metaclass/checked_demo.py\r\n```\r\n#!/usr/bin/env python3\r\n\r\n# tag::MOVIE_DEMO[]\r\nfrom checkedlib import Checked\r\n\r\nclass Movie(Checked):\r\n title: str\r\n year: int\r\n box_office: float\r\n\r\nif __name__ == '__main__':\r\n movie = Movie(title='The Godfather', year=1972, box_office=137)\r\n print(movie)\r\n print(movie.title)\r\n # end::MOVIE_DEMO[]\r\n\r\n try:\r\n # remove the \"type: ignore\" comment to see Mypy error\r\n movie.year = 'MCMLXXII' # type: ignore\r\n except TypeError as e:\r\n print(e)\r\n try:\r\n blockbuster = Movie(title='Avatar', year=2009, box_office='billions')\r\n except TypeError as e:\r\n print(e)\r\n\r\n```\r\nThere is a TypeError:\r\n```\r\n---------------------------------------------------------------------------\r\nTypeError Traceback (most recent call last)\r\nInput In [2], in \u003ccell line: 6>()\r\n 1 #!/usr/bin/env python3\r\n 2 \r\n 3 # tag::MOVIE_DEMO[]\r\n 4 from checkedlib import Checked\r\n----> 6 class Movie(Checked):\r\n 7 title: str\r\n 8 year: int\r\n\r\nFile D:\\books/python/0. Fluent Python, 2nd Edition/example-code-2e/24-class-metaprog/checked/metaclass\\checkedlib.py:107, in CheckedMeta.__new__(meta_cls, cls_name, bases, cls_dict)\r\n 105 type_hints = cls_dict.get('__annotations__', {}) # \u003c3>\r\n 106 for name, constructor in type_hints.items(): # \u003c4>\r\n--> 107 field = Field(name, constructor) # \u003c5>\r\n 108 cls_dict[name] = field # \u003c6>\r\n 109 slots.append(field.storage_name) # \u003c7>\r\n\r\nFile D:\\books/python/0. Fluent Python, 2nd Edition/example-code-2e/24-class-metaprog/checked/metaclass\\checkedlib.py:76, in Field.__init__(self, name, constructor)\r\n 74 def __init__(self, name: str, constructor: Callable) -> None:\r\n 75 if not callable(constructor) or constructor is type(None):\r\n---> 76 raise TypeError(f'{name!r} type hint must be callable')\r\n 77 self.name = name\r\n 78 self.storage_name = '_' + name # \u003c1>\r\n\r\nTypeError: 'title' type hint must be callable\r\n```\r\n\r\nMy python version is Python 3.8.13.\r\n\r\nThanks\r\n\r\n","author":{"url":"https://github.com/danli349","@type":"Person","name":"danli349"},"datePublished":"2022-11-29T14:35:17Z","url":"https://github.com/fluentpython/example-code-2e/issues/30"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:aad0a23d-cd68-123b-5125-15a93e8700cb |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C2F2:26E336:3C9854:51A794:6B06770A |
| html-safe-nonce | d8152afa2392518d03a172a2b4db92e1a1f128c1456bae6d6effe3caf49fe70a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMkYyOjI2RTMzNjozQzk4NTQ6NTFBNzk0OjZCMDY3NzBBIiwidmlzaXRvcl9pZCI6IjUwNjY5NzI2OTI3MDA2MjQ2NTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 47b36678bf8178f0e753ecc42237b75b6540b3aebb91c255780789a1f89d39f4 |
| hovercard-subject-tag | issue:1468172748 |
| 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/30/issue_layout |
| twitter:image | https://opengraph.githubassets.com/721700d150f0b584d9d1be4a130b16742ac7a433ae71d1a9169e069559af5d4d/fluentpython/example-code-2e/issues/30 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/721700d150f0b584d9d1be4a130b16742ac7a433ae71d1a9169e069559af5d4d/fluentpython/example-code-2e/issues/30 |
| og:image:alt | Hello, I run the code in https://github.com/fluentpython/example-code-2e/tree/master/24-class-metaprog/checked/metaclass/checked_demo.py #!/usr/bin/env python3 # tag::MOVIE_DEMO[] from checkedlib i... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | danli349 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4462ff7ebfd3d551f202659f2423dae617b6849d23b1df6465dc504ef497d14a |
| 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 | 6d3909414814ff86ce7da4c51a0f4918a13fb41b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width