Title: Prevent an implementation for `int` class from operating on `bool` values · Issue #310 · dry-python/classes · GitHub
Open Graph Title: Prevent an implementation for `int` class from operating on `bool` values · Issue #310 · dry-python/classes
X Title: Prevent an implementation for `int` class from operating on `bool` values · Issue #310 · dry-python/classes
Description: Context. Consider the following piece of code. from classes import typeclass @typeclass def render(data_value) -> str: """Pretty-print a value.""" @render.instance(int) def _render_int(data_value: int) -> str: return f'🔢 {data_value}' re...
Open Graph Description: Context. Consider the following piece of code. from classes import typeclass @typeclass def render(data_value) -> str: """Pretty-print a value.""" @render.instance(int) def _render_int(data_value: ...
X Description: Context. Consider the following piece of code. from classes import typeclass @typeclass def render(data_value) -> str: """Pretty-print a value.""" @render.instance(...
Opengraph URL: https://github.com/dry-python/classes/issues/310
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Prevent an implementation for `int` class from operating on `bool` values","articleBody":"**Context.** Consider the following piece of code.\r\n\r\n```python\r\nfrom classes import typeclass\r\n\r\n@typeclass\r\ndef render(data_value) -\u003e str:\r\n \"\"\"Pretty-print a value.\"\"\"\r\n\r\n@render.instance(int)\r\ndef _render_int(data_value: int) -\u003e str:\r\n return f'🔢 {data_value}'\r\n\r\nrender(True) == '🔢 True'\r\n```\r\n*(this should be runnable as-is on `classes 0.4.0`.)*\r\n\r\nI would have expected this code to fail with a `NotImplementedError` because the `bool` case wasn't specified; but instead, that case is handled by the `int` implementation because\r\n\r\n```pycon\r\nIn [3]: issubclass(bool, int)\r\nOut[3]: True\r\n```\r\n\r\n**Decision.** In an `int` implementation, recognize if the provided value is actually a `bool` and refuse to process that value.\r\n\r\n**Consequences.** I have been writing in Python for quite a few years now and I might even have encountered this relationship between `int` and `bool` types before, but that is not quite a type of thing that I keep in my short-term memory to be able to instantly recognize.\r\n\r\nI believe this change can help avert bugs which might be hard to trace otherwise.","author":{"url":"https://github.com/anatoly-scherbakov","@type":"Person","name":"anatoly-scherbakov"},"datePublished":"2021-09-13T13:27:33.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/310/classes/issues/310"}
| 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:059ee399-d1b8-c37b-2405-5f5e9a80369e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E342:1E165C:8B6B67:BB9060:69697A4A |
| html-safe-nonce | ded075aa4d39c33517088aea67ddc9b96518e3d4ae3478c423db8e2e0d862239 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMzQyOjFFMTY1Qzo4QjZCNjc6QkI5MDYwOjY5Njk3QTRBIiwidmlzaXRvcl9pZCI6IjY0MjI3OTIxNTAzMTAyODc5NDYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 2f7b2c3b081fd1c3686dbf8c11323b3363c45131c33f8439335a33872ed829c2 |
| hovercard-subject-tag | issue:994893424 |
| 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/dry-python/classes/310/issue_layout |
| twitter:image | https://opengraph.githubassets.com/96787c0e82ef1d504cf2d25ddc3708eb01d130ddd7b9fd696a6a0a811829a7ad/dry-python/classes/issues/310 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/96787c0e82ef1d504cf2d25ddc3708eb01d130ddd7b9fd696a6a0a811829a7ad/dry-python/classes/issues/310 |
| og:image:alt | Context. Consider the following piece of code. from classes import typeclass @typeclass def render(data_value) -> str: """Pretty-print a value.""" @render.instance(int) def _render_int(data_value: ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | anatoly-scherbakov |
| hostname | github.com |
| expected-hostname | github.com |
| None | c6f193beb8ff08443adc07685d75302ab8aaf0a135f6e251c3ff3112c8deb881 |
| turbo-cache-control | no-preview |
| go-import | github.com/dry-python/classes git https://github.com/dry-python/classes.git |
| octolytics-dimension-user_id | 37993755 |
| octolytics-dimension-user_login | dry-python |
| octolytics-dimension-repository_id | 217621930 |
| octolytics-dimension-repository_nwo | dry-python/classes |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 217621930 |
| octolytics-dimension-repository_network_root_nwo | dry-python/classes |
| 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 | 212e3e3d3298bf5b313830edfd2399e869f7ea76 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width