Title: Ignore typing errors in individual blocks · Issue #6948 · python/mypy · GitHub
Open Graph Title: Ignore typing errors in individual blocks · Issue #6948 · python/mypy
X Title: Ignore typing errors in individual blocks · Issue #6948 · python/mypy
Description: It is already possible to silence errors using # type: ignore on individual lines, and - since #626) also for a whole file. Additionally it would be nice to ignore errors on individual blocks. Especially on a class/function level when ab...
Open Graph Description: It is already possible to silence errors using # type: ignore on individual lines, and - since #626) also for a whole file. Additionally it would be nice to ignore errors on individual blocks. Espe...
X Description: It is already possible to silence errors using # type: ignore on individual lines, and - since #626) also for a whole file. Additionally it would be nice to ignore errors on individual blocks. Espe...
Opengraph URL: https://github.com/python/mypy/issues/6948
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Ignore typing errors in individual blocks","articleBody":"It is already possible to silence errors using `# type: ignore` on individual lines, and - since #626) also for a whole file.\r\n\r\nAdditionally it would be nice to ignore errors on individual blocks. Especially on a class/function level when abstracting away an untyped library. For example:\r\n\r\n class MyAbstraction:\r\n\r\n def __init__(self, url: str) -\u003e None:\r\n self.hostname = url.host # \u003c-- I want this to be caught by the type-checker\r\n\r\n def some_call(self) -\u003e int:\r\n # type: ignore\r\n result = api.untyped_call()\r\n return result\r\n\r\n def another_large_call(self) -\u003e int:\r\n # type: ignore\r\n result_1 = api.untyped_call_1()\r\n result_2 = api.untyped_call_2()\r\n result = result_1 + result_2\r\n return result\r\n\r\nWhen running `mypy` in \"strict\" mode the code will be littered with messages like `Call to an untyped function ... in a typed context`. Currently the only options are:\r\n\r\n* Add `# type: ignore` on each line causing errors by the external library\r\n * Disadvantage: Cumbersome (many type-comments needed)\r\n * Advantage: Only the problematic calls are silenced\r\n* Add `# type: ignore` to the file\r\n * Disadvantage: Typing errors unrelated to the external library become invisible\r\n * Advantage: Only one line to add\r\n\r\nThe second option is best used if a module contains *only* calls to the external library. For new projects this is doable, but older/larger code-bases often need some refactoring for this. And this can be error-prone and seems risky to do *only* for type-hinting.\r\n\r\nHaving the option to disable errors on either a class-level or block-level would add a lot of flexibility.","author":{"url":"https://github.com/exhuma","@type":"Person","name":"exhuma"},"datePublished":"2019-06-07T12:25:15.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":22},"url":"https://github.com/6948/mypy/issues/6948"}
| 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:d3e1d226-a679-4abb-c07c-8e9a41905277 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D06A:B33E1:155334C:1E0ED40:6A574C19 |
| html-safe-nonce | e454dd51af7297a7c49de7601a295ea056d4e1b0d5f0d64c105dfc157b63ede5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMDZBOkIzM0UxOjE1NTMzNEM6MUUwRUQ0MDo2QTU3NEMxOSIsInZpc2l0b3JfaWQiOiIxNDU1MzIxODQyOTQwNTk1MjI1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | e8396b9af299e7f268d31f33bda5bf5e0fee73a747612aa7505975e0b0f96053 |
| hovercard-subject-tag | issue:453487258 |
| 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/6948/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7dac1fd82f70673601d81a1211244e677c1c711f43c6e904aedfb52be69ea8bb/python/mypy/issues/6948 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7dac1fd82f70673601d81a1211244e677c1c711f43c6e904aedfb52be69ea8bb/python/mypy/issues/6948 |
| og:image:alt | It is already possible to silence errors using # type: ignore on individual lines, and - since #626) also for a whole file. Additionally it would be nice to ignore errors on individual blocks. Espe... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | exhuma |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4e7a7296a3830877cf21a6ad2a972c9e618a48915e03966cf0c53eb08e5aad98 |
| 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 | 602250ea3b6dd8302a7220ef98adb828dbc807e4 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width