Title: __ceil__, __floor__ and numbers.Real · Issue #3195 · python/typeshed · GitHub
Open Graph Title: __ceil__, __floor__ and numbers.Real · Issue #3195 · python/typeshed
X Title: __ceil__, __floor__ and numbers.Real · Issue #3195 · python/typeshed
Description: PR #3108 (originally) tried to make float a subclass of numbers.Real. Two method implementations were missing, __floor__ and __ceil__ (cpython). These do exist for int and Decimal etc., but @srittau noticed that they actually do not exis...
Open Graph Description: PR #3108 (originally) tried to make float a subclass of numbers.Real. Two method implementations were missing, __floor__ and __ceil__ (cpython). These do exist for int and Decimal etc., but @sritta...
X Description: PR #3108 (originally) tried to make float a subclass of numbers.Real. Two method implementations were missing, __floor__ and __ceil__ (cpython). These do exist for int and Decimal etc., but @sritta...
Opengraph URL: https://github.com/python/typeshed/issues/3195
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"__ceil__, __floor__ and numbers.Real","articleBody":"PR #3108 (originally) tried to make `float` a subclass of `numbers.Real`. Two method implementations were missing, `__floor__` and `__ceil__` ([cpython](https://github.com/python/cpython/blob/29bb227a0ce6d355a2b3e5d6a25872e3702ba9bb/Lib/numbers.py#L178-L186)). These do exist for `int` and `Decimal` etc., but @srittau noticed that they actually do *not* exist for `float` itself, therefore they cannot be added to `float`'s stubs, and `float` cannot be made to conform to `numbers.Real`.\r\n\r\n---\r\n\r\nI did some digging and found that abstractly `numbers.Real` really just wants `math.floor()` and `math.ceil()` to work. And in cpython, these two functions work something like this (using `floor` ):\r\n\r\n1. If the argument is a `float`, do the operation directly in C code.\r\n2. Else, if the argument has a `__floor__` method, use it.\r\n3. Else, if the argument has a `__float__` method, use it and go to (1).\r\n\r\nAs it happen, `numbers.Real` does require `__float__()` to be implemented. So as a workaround for this issue, I proposed removing `__floor__` and `__ceil__` from typeshed's `numbers.Real` stub, since the `__float__` fallback can be relied on instead.\r\n\r\n---\r\n\r\nAnother view is that this is a cpython issue and should be fixed there.\r\n\r\n---\r\n\r\nAnd another view is that `numbers` is a lost cause for static typing and should just be ignored or replaced with something better (like protocols).","author":{"url":"https://github.com/bluetech","@type":"Person","name":"bluetech"},"datePublished":"2019-08-17T09:57:48Z","url":"https://github.com/python/typeshed/issues/3195"}
| 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:308139e5-42e4-c8db-5bf3-50ce2563a695 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C218:142FA7:99975:CE6E3:6B001BE9 |
| html-safe-nonce | 59d7d5fa5f589f369992e741c6307991371c4dc265a54353f348a7c8b66f6722 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMjE4OjE0MkZBNzo5OTk3NTpDRTZFMzo2QjAwMUJFOSIsInZpc2l0b3JfaWQiOiI5MTE0MTA5NTEyNzI1MzcwNjUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 502a33d148faa2d1320b2c63e89ced4ebd8f627ee7f025b4ae3e47cdbcd6b984 |
| hovercard-subject-tag | issue:481870111 |
| 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/python/typeshed/3195/issue_layout |
| twitter:image | https://opengraph.githubassets.com/89769b7c0c6d7637c7c07af53ec8b6cd136fae7c6356f23b29b8e1ff2e7b38ae/python/typeshed/issues/3195 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/89769b7c0c6d7637c7c07af53ec8b6cd136fae7c6356f23b29b8e1ff2e7b38ae/python/typeshed/issues/3195 |
| og:image:alt | PR #3108 (originally) tried to make float a subclass of numbers.Real. Two method implementations were missing, __floor__ and __ceil__ (cpython). These do exist for int and Decimal etc., but @sritta... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bluetech |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typeshed git https://github.com/python/typeshed.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 31696383 |
| octolytics-dimension-repository_nwo | python/typeshed |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 31696383 |
| octolytics-dimension-repository_network_root_nwo | python/typeshed |
| 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 | 44c658b24abf00491fb7ae5f56d42c9f38cbeab2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width