Title: abs(Union[int, Decimal]) is inferred as object · Issue #8601 · python/mypy · GitHub
Open Graph Title: abs(Union[int, Decimal]) is inferred as object · Issue #8601 · python/mypy
X Title: abs(Union[int, Decimal]) is inferred as object · Issue #8601 · python/mypy
Description: I'm afraid I'm not sure whether I'm reporting a bug or requesting a feature. I'm happy to leave that up for you all to triage. I'll start with what I'm seeing and what I'd like to see, and then get a little bit into the why. Here's a min...
Open Graph Description: I'm afraid I'm not sure whether I'm reporting a bug or requesting a feature. I'm happy to leave that up for you all to triage. I'll start with what I'm seeing and what I'd like to see, and then get...
X Description: I'm afraid I'm not sure whether I'm reporting a bug or requesting a feature. I'm happy to leave that up for you all to triage. I'll start with what I'm seeing and what I'...
Opengraph URL: https://github.com/python/mypy/issues/8601
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"abs(Union[int, Decimal]) is inferred as object","articleBody":"I'm afraid I'm not sure whether I'm reporting a bug or requesting a feature. I'm happy to leave that up for you all to triage. I'll start with what I'm seeing and what I'd like to see, and then get a little bit into the why.\r\n\r\nHere's a minimal reproduction:\r\n\r\n```python\r\nfrom decimal import Decimal\r\nfrom typing import Union\r\n\r\ndef check(x: Decimal, y: Union[Decimal, int]) -> bool:\r\n return x \u003c -abs(y)\r\n```\r\n\r\nWith Python 3.7.3 (from Debian buster) and mypy 0.770 (from PyPI), checking this code returns an error:\r\n\r\n```\r\ndeccomp.py:6: error: Unsupported operand type for unary - (\"object\") [operator]\r\nFound 1 error in 1 file (checked 1 source file)\r\n```\r\n\r\nThe return type of `abs` is inferred as object, I think because that's the common supertype of int and Decimal. It would be nice if, one way or another, the return type of `abs` could be inferred as some higher numeric type.\r\n\r\nThe context here is I'm working on accounting software where I want to be careful to do decimal math throughout. In other words, I never want to deal with the decimal.FloatOperation signal. For functions that do basic arithmetic or comparisons across numbers, it's fine to accept arguments that are either int or Decimal, and it's convenient for callers if I can annotate that argument type rather than requiring them to convert their integer arguments to Decimal all the time.","author":{"url":"https://github.com/brettcs","@type":"Person","name":"brettcs"},"datePublished":"2020-03-29T19:25:43Z","url":"https://github.com/python/mypy/issues/8601"}
| 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:b7d0acd2-b20c-1df3-fda9-acc55a54ffb6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8CB6:3DCBB0:D5B8A:12BC79:6B00634E |
| html-safe-nonce | 34c679f7251d1bda893dfadc5f107808749a6fbc4076dffedb2f009b8f86900a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4Q0I2OjNEQ0JCMDpENUI4QToxMkJDNzk6NkIwMDYzNEUiLCJ2aXNpdG9yX2lkIjoiMTYwMzIwMDg0Mjk4OTgyMjIyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 34965dfd061b5e0b9e9f5d0de3622a76c7f7ef3249beedf88a49b223540bdb23 |
| hovercard-subject-tag | issue:589864361 |
| 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/mypy/8601/issue_layout |
| twitter:image | https://opengraph.githubassets.com/dc21dbb3bc8072a3b115f439b54b123da72d045f31ddb3c6adfc591394acb72e/python/mypy/issues/8601 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/dc21dbb3bc8072a3b115f439b54b123da72d045f31ddb3c6adfc591394acb72e/python/mypy/issues/8601 |
| og:image:alt | I'm afraid I'm not sure whether I'm reporting a bug or requesting a feature. I'm happy to leave that up for you all to triage. I'll start with what I'm seeing and what I'd like to see, and then get... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | brettcs |
| hostname | github.com |
| expected-hostname | github.com |
| None | 25854482a1773a7c1ebb8be3d2bc1c6e61d82d78126be63b5044474a86d44d9e |
| turbo-cache-control | no-preview |
| go-import | github.com/python/mypy git https://github.com/python/mypy.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 7053637 |
| octolytics-dimension-repository_nwo | python/mypy |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 7053637 |
| octolytics-dimension-repository_network_root_nwo | python/mypy |
| 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 | e4f5c239e31f1f680e6bbc419ff92d774da616ec |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width