Title: sys.exit and SystemExit · Issue #8513 · python/typeshed · GitHub
Open Graph Title: sys.exit and SystemExit · Issue #8513 · python/typeshed
X Title: sys.exit and SystemExit · Issue #8513 · python/typeshed
Description: sys.exit() is defined as: typeshed/stdlib/sys.pyi Lines 224 to 225 in c68bcc7 # sys.exit() accepts an optional argument of anything printable def exit(__status: object = ...) -> NoReturn: ... The argument ends up in the .code attribute o...
Open Graph Description: sys.exit() is defined as: typeshed/stdlib/sys.pyi Lines 224 to 225 in c68bcc7 # sys.exit() accepts an optional argument of anything printable def exit(__status: object = ...) -> NoReturn: ... The a...
X Description: sys.exit() is defined as: typeshed/stdlib/sys.pyi Lines 224 to 225 in c68bcc7 # sys.exit() accepts an optional argument of anything printable def exit(__status: object = ...) -> NoReturn: ... Th...
Opengraph URL: https://github.com/python/typeshed/issues/8513
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"sys.exit and SystemExit","articleBody":"`sys.exit()` is defined as:\r\n\r\nhttps://github.com/python/typeshed/blob/c68bcc7e69249956f358da7f47028d8fd1f7443e/stdlib/sys.pyi#L224-L225\r\n\r\nThe argument ends up in the `.code` attribute of a `SystemExit` exception.\r\n\r\n```python3\r\n\u003e\u003e\u003e import sys\r\n\u003e\u003e\u003e try: sys.exit()\r\n... except SystemExit as e: print(repr(e.code))\r\n... \r\nNone\r\n\u003e\u003e\u003e try: sys.exit(\"lol\")\r\n... except SystemExit as e: print(repr(e.code))\r\n... \r\n'lol'\r\n\u003e\u003e\u003e try: sys.exit({\"foo\": \"bar\"})\r\n... except SystemExit as e: print(repr(e.code))\r\n... \r\n{'foo': 'bar'}\r\n```\r\n\r\nBut that's typed as:\r\n\r\nhttps://github.com/python/typeshed/blob/c68bcc7e69249956f358da7f47028d8fd1f7443e/stdlib/builtins.pyi#L1793-L1794\r\n\r\nThese should be the same IMO, but what should they be? The interpreter handles uncaught `SystemExit` exceptions like this:\r\n- If the `code` is `None`, exit the process with status zero.\r\n- If the `code` is an integer, exit the process with that status.\r\n- Otherwise, print the `code` (to stderr) and exit the process with status `1`.\r\n\r\nI'd suggest using `str | int | None`, where we use `str` because we don't have any way to express \"anything reasonably printable\" without saying \"any object\". This way you can use each of the interpreter's behaviors as intended, and if you accidentally pass in e.g. `0.0`, the type checker will warn you instead of making you wonder why your process printed `0.0` and failed.","author":{"url":"https://github.com/Akuli","@type":"Person","name":"Akuli"},"datePublished":"2022-08-09T19:04:42.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/8513/typeshed/issues/8513"}
| 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:d3d3bc6d-1f33-51fa-5728-67416bce2200 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8F72:240924:CA430A:10F32DC:6A62B28F |
| html-safe-nonce | 303c2bd61a96c0be225f7fb77c343d9823c44fc6b41c4247dd83f6847d176be1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RjcyOjI0MDkyNDpDQTQzMEE6MTBGMzJEQzo2QTYyQjI4RiIsInZpc2l0b3JfaWQiOiI0OTQxNjU1MDU2MDUwMjA1MzI3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | c66ed22f03445fc959d1eff442862fe900f9ff2f44afdfdfa030a78ff6a4da20 |
| hovercard-subject-tag | issue:1333671093 |
| 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/8513/issue_layout |
| twitter:image | https://opengraph.githubassets.com/43edb5303ba6b8b8690f300fcbb67bce78d029e2f4aa20c9f91eaaa7ea15b05c/python/typeshed/issues/8513 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/43edb5303ba6b8b8690f300fcbb67bce78d029e2f4aa20c9f91eaaa7ea15b05c/python/typeshed/issues/8513 |
| og:image:alt | sys.exit() is defined as: typeshed/stdlib/sys.pyi Lines 224 to 225 in c68bcc7 # sys.exit() accepts an optional argument of anything printable def exit(__status: object = ...) -> NoReturn: ... The a... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Akuli |
| hostname | github.com |
| expected-hostname | github.com |
| None | 2738d7125e864b55224a8bc40c72c220ca7d2c73f91a7bb8d69dffe9d35e997d |
| 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 | bf54af498459157b66a67136f992a68752cdbb54 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width