Title: Support `Any` as an alias for `object` to describe a default typeclass implementation · Issue #307 · dry-python/classes · GitHub
Open Graph Title: Support `Any` as an alias for `object` to describe a default typeclass implementation · Issue #307 · dry-python/classes
X Title: Support `Any` as an alias for `object` to describe a default typeclass implementation · Issue #307 · dry-python/classes
Description: Context. In order to define a default implementation (the one used if no other implementation matches), we currently have to write something like this: from classes import typeclass @typeclass def render(data_value) -> str: """Render a d...
Open Graph Description: Context. In order to define a default implementation (the one used if no other implementation matches), we currently have to write something like this: from classes import typeclass @typeclass def ...
X Description: Context. In order to define a default implementation (the one used if no other implementation matches), we currently have to write something like this: from classes import typeclass @typeclass def ...
Opengraph URL: https://github.com/dry-python/classes/issues/307
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Support `Any` as an alias for `object` to describe a default typeclass implementation","articleBody":"**Context.** In order to define a default implementation (the one used if no other implementation matches), we currently have to write something like this:\r\n\r\n```python\r\nfrom classes import typeclass\r\n\r\n@typeclass\r\ndef render(data_value) -\u003e str:\r\n \"\"\"Render a data value nicely.\"\"\"\r\n\r\n@render.instance(int)\r\ndef _render_int(data_value: int) -\u003e str:\r\n return f'This is an integer: {data_value}'\r\n\r\n\r\n@render.instance(object)\r\ndef _render_int(data_value: object) -\u003e str:\r\n return f'No idea what this is: {data_value}'\r\n\r\n\r\nassert render('BADOOM') == 'No idea what this is: BADOOM'\r\n```\r\n*(this script should be runnable as-is.)*\r\n\r\n**Decision.** Support `Any` as a special case to replace `object`:\r\n\r\n```python\r\n@render.instance(Any)\r\ndef _render_int(data_value: Any) -\u003e str: # type: ignore\r\n return f'No idea what this is: {data_value}'\r\n```\r\n\r\n**Consequences.**\r\n* Pro: The code will look a little bit more straightforward;\r\n* Contra: `mypy` with common settings might be unhappy about `Any` being used, but that can be silenced with `type: ignore` I suppose.","author":{"url":"https://github.com/anatoly-scherbakov","@type":"Person","name":"anatoly-scherbakov"},"datePublished":"2021-09-13T13:03:39.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/307/classes/issues/307"}
| 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:d04ca268-2a39-8968-9d96-17927086ffcd |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C3E8:A74F2:87E747:B58C39:69697A27 |
| html-safe-nonce | b5bf846500d6937c30fbea10fbaf930564c6fee4f2d949ef40098609fe82c20a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDM0U4OkE3NEYyOjg3RTc0NzpCNThDMzk6Njk2OTdBMjciLCJ2aXNpdG9yX2lkIjoiMjM4MDcxODA4MjA5MTQ4MTYzOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d0e96245620334a83b2784706be99959be814d3831041c148878ae10ce5161ab |
| hovercard-subject-tag | issue:994865351 |
| 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/307/issue_layout |
| twitter:image | https://opengraph.githubassets.com/88f37d262a8496371a6c3b659073837c9dbaa02434b6f166dc80585cf268b7f2/dry-python/classes/issues/307 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/88f37d262a8496371a6c3b659073837c9dbaa02434b6f166dc80585cf268b7f2/dry-python/classes/issues/307 |
| og:image:alt | Context. In order to define a default implementation (the one used if no other implementation matches), we currently have to write something like this: from classes import typeclass @typeclass def ... |
| 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