René's URL Explorer Experiment


Title: Support error codes and ignoring only specific errors · Issue #7239 · python/mypy · GitHub

Open Graph Title: Support error codes and ignoring only specific errors · Issue #7239 · python/mypy

X Title: Support error codes and ignoring only specific errors · Issue #7239 · python/mypy

Description: It would be handy to support error codes to allow ignoring only specific error messages on each line. For example, here we only ignore an error about an incompatible override in class B: class A: def f(self) -> None: ... class B(A): def ...

Open Graph Description: It would be handy to support error codes to allow ignoring only specific error messages on each line. For example, here we only ignore an error about an incompatible override in class B: class A: d...

X Description: It would be handy to support error codes to allow ignoring only specific error messages on each line. For example, here we only ignore an error about an incompatible override in class B: class A: d...

Opengraph URL: https://github.com/python/mypy/issues/7239

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Support error codes and ignoring only specific errors","articleBody":"It would be handy to support error codes to allow ignoring only specific error messages on each line. For example, here we only ignore an error about an incompatible override in class `B`:\r\n\r\n```py\r\nclass A:\r\n    def f(self) -> None: \r\n        ...\r\n\r\nclass B(A):\r\n    def f(self, x: int) -> None:  # type: ignore[override]\r\n        ...\r\n```\r\n\r\nIf there are any other errors on that line (such as \"invalid type\"), they will still be reported. Using the existing blanket `# type: ignore` comment risks ignoring too many errors, resulting in false negatives.\r\n\r\nFor this we need these changes:\r\n\r\n1. Make it possible to display error codes with errors (either optionally or by default).\r\n2. Support ignoring specific errors using `# type: ignore[code1, ..., codeN]`.\r\n3. Implement error codes for all common errors (at least).\r\n\r\nThis is potentially a pretty disruptive change, so we need to be careful about how to do this. Here are some ideas. There is an existing PR that implements some of this (#6472). My proposal differs in various details, but the end goal is the same.\r\n\r\n**Format of error codes.** There are various options such as numeric codes, strings derived from messages (as in #6472), and short error identifiers that are chosen manually. I'm leaning towards the final option. I'd like error codes to be pretty short but still understandable, and perhaps even memorable. I'm proposing that most error codes are of the form `foo`, `foo-bar` or `foo-bar-lulz` (one to three words separated by dashes). \r\n\r\n**Granularity of error codes.** I think that not every error message needs a separate code, since this could mean hundreds of different codes. The number of codes should small enough that the list of all codes is easy enough to browse. I'm thinking of maybe having 20-50 distinct error codes in the long term. We don't need a unique error code for every rare message. We can either use a category code (such as `indexing` for various errors related to `x[y]` expressions) or a fallback misc/other category for all unclassified errors. The misc/other category also makes adoption easy -- we can initially have lots of errors in this category, and gradually migrate additional errors to more specific codes.\r\n\r\n**Displaying error codes.** We could display error codes like this in mypy output:\r\n\r\n```\r\nfoo.py:124: error: Some bad stuff going on here [bad-stuff]\r\n```\r\n\r\nThe rationale is that the error code is *usually* not important, so we shouldn't make it too prominent. This is also one of the reasons why the error codes should be pretty short. This way we could probably enable error codes by default, as they are perhaps not too distracting.\r\n\r\n**Implementing error codes.** My idea would be to have error codes totally separate from error messages. Each error reporting call would optionally include the error code (it would default to a generic other/misc category code). Error codes would defined with some metadata in a new error code registry module. The metadata could be used for grouping and help output. Here's a rough idea (this will need some iteration):\r\n\r\n```py\r\n# Arguments are 1) error code 2) description in help output 3) category\r\nBAD_STUFF = ErrorCode('bad-stuff', 'Bad stuff going on', 'General')\r\n```\r\n\r\nThe motivation is that no dynamic magic is required, and everything is very explicit.\r\n\r\n**Errors from plugins.** I haven't thought about this much, but plugins should be able to provide a list of error code objects. These could be shown in the error code help output. Maybe plugins should generally define relatively few error codes per plugin. It would be okay to just have a single error code for all errors from a plugin, and plugins can also reuse predefined error codes.\r\n\r\n**Sample error codes.** Here are few actual error codes we might want to define (these are not final and may need iteration):\r\n\r\n```\r\n\"x\" has no attribute \"y\" [attr-defined]\r\nUnexpected keyword argument \"x\" for \"y\" [call-arg]\r\nSignature of \"x\" incompatible with supertype \"x\" [override]\r\nFunction is missing a type annotation [no-untyped-def]\r\n```\r\n\r\nThe idea is that the name of the error code typically refers to what is being checked (whether an attribute is defined; whether an argument is valid in a call; validity of a method override). Short names are preferred, as long as they are sufficiently descriptive. For errors from optional strictness options we name the error code `no-x`, where `x` refers to what is being disallowed.\r\n\r\n**Postponed topics.** We could also migrate some existing strictness flags to error codes, and to allow enabling and disabling particular errors globally or per file. These feel less important than being able to ignore specific errors on a line right now, but they would be nice features to have. We'll also want a way to display all available error codes through a command line option, but again this isn't required initially.\r\n\r\n**Next steps.** I'm planning to implement this soon, since we have a use case which requires this feature at Dropbox. I can reuse some code and ideas from #6472 if @chadrik isn't opposed to it.\r\n\r\ncc @chadrik","author":{"url":"https://github.com/JukkaL","@type":"Person","name":"JukkaL"},"datePublished":"2019-07-18T16:50:06Z","url":"https://github.com/python/mypy/issues/7239"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:1d7e7544-eac7-e1ca-d3fd-0dae36d6c837
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE5D4:61A3E:36572D:4A20E5:6B006C14
html-safe-nonce069d0f39712187842abaeff7d1ea2c49415de98e18f8733418102daf78d1a03c
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNUQ0OjYxQTNFOjM2NTcyRDo0QTIwRTU6NkIwMDZDMTQiLCJ2aXNpdG9yX2lkIjoiNTM4MDg4MDg0MDA2ODcyMTY4NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacca2279b7d823cccd5b2a2b0a70b1939d98ead7c167d9e941bbed37c400b64e4f
hovercard-subject-tagissue:469878295
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/mypy/7239/issue_layout
twitter:imagehttps://opengraph.githubassets.com/3279e1ddd9b873e9dfb4124f310b726e3fde5cdb4f96a53d4150ba0a3681f0e3/python/mypy/issues/7239
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/3279e1ddd9b873e9dfb4124f310b726e3fde5cdb4f96a53d4150ba0a3681f0e3/python/mypy/issues/7239
og:image:altIt would be handy to support error codes to allow ignoring only specific error messages on each line. For example, here we only ignore an error about an incompatible override in class B: class A: d...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameJukkaL
hostnamegithub.com
expected-hostnamegithub.com
None6527e91c60c0b29d16606ff32ac5df8ecdc37a2a62205ea057a14d7762c870fa
turbo-cache-controlno-preview
go-importgithub.com/python/mypy git https://github.com/python/mypy.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id7053637
octolytics-dimension-repository_nwopython/mypy
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id7053637
octolytics-dimension-repository_network_root_nwopython/mypy
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release46f1cd2ae3cd8ae1a81019b5d619742e76f13bbd
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/mypy/issues/7239#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fmypy%2Fissues%2F7239
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fmypy%2Fissues%2F7239
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fmypy
Reloadhttps://github.com/python/mypy/issues/7239
Reloadhttps://github.com/python/mypy/issues/7239
Reloadhttps://github.com/python/mypy/issues/7239
pythonhttps://github.com/python
mypyhttps://github.com/python/mypy
Codehttps://github.com/python/mypy
Issues2.7k (2.7k)https://github.com/python/mypy/issues
Pull requests543 (543)https://github.com/python/mypy/pulls
Actionshttps://github.com/python/mypy/actions
Projectshttps://github.com/python/mypy/projects
Wikihttps://github.com/python/mypy/wiki
Security and qualityhttps://github.com/python/mypy/security
Insightshttps://github.com/python/mypy/insights
https://github.com/python/mypy
New issuehttps://github.com/login?return_to=https://github.com/python/mypy/issues/7239
New issuehttps://github.com/login?return_to=https://github.com/python/mypy/issues/7239
Support error codes and ignoring only specific errorshttps://github.com/python/mypy/issues/7239#top
https://github.com/JukkaL
featurehttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22feature%22
priority-0-highhttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22priority-0-high%22
https://github.com/JukkaL
JukkaLhttps://github.com/JukkaL
on Jul 18, 2019https://github.com/python/mypy/issues/7239#issue-469878295
#6472https://github.com/python/mypy/pull/6472
#6472https://github.com/python/mypy/pull/6472
#6472https://github.com/python/mypy/pull/6472
@chadrikhttps://github.com/chadrik
@chadrikhttps://github.com/chadrik
JukkaLhttps://github.com/JukkaL
featurehttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22feature%22
priority-0-highhttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22priority-0-high%22
on Jul 18, 2019https://github.com/python/mypy/issues/7239#event-2493368612
https://github.com/chadrik
chadrikhttps://github.com/chadrik
on Jul 18, 2019https://github.com/python/mypy/issues/7239#issuecomment-512907490
https://github.com/chadrik/mypy-runner/blob/master/mypyrun.pyhttps://github.com/chadrik/mypy-runner/blob/master/mypyrun.py
https://github.com/JukkaL
JukkaLhttps://github.com/JukkaL
on Jul 19, 2019https://github.com/python/mypy/issues/7239#issuecomment-513181673
https://github.com/ilevkivskyi
ilevkivskyihttps://github.com/ilevkivskyi
on Jul 19, 2019https://github.com/python/mypy/issues/7239#issuecomment-513273329
msullivanhttps://github.com/msullivan
on Jul 19, 2019https://github.com/python/mypy/issues/7239#event-2497095981
In PEP 484 type comments, allow text after "# type: ignore"https://github.com/msullivan/pyflakes/commit/141947f071cf91b2bfa90a46da36174081ef1587
141947fhttps://github.com/msullivan/pyflakes/commit/141947f071cf91b2bfa90a46da36174081ef1587
In PEP 484 type comments, allow text after "# type: ignore"https://github.com/msullivan/pyflakes/commit/e6905ee10a89d86ac429f1ddd1ee573f2f8c7293
e6905eehttps://github.com/msullivan/pyflakes/commit/e6905ee10a89d86ac429f1ddd1ee573f2f8c7293
In PEP 484 type comments, allow text after "# type: ignore"https://github.com/msullivan/pyflakes/commit/b9267e139cb5ce0bfaa189c0ab7597afb9e90ec5
b9267e1https://github.com/msullivan/pyflakes/commit/b9267e139cb5ce0bfaa189c0ab7597afb9e90ec5
JukkaLhttps://github.com/JukkaL
on Jul 26, 2019https://github.com/python/mypy/issues/7239#event-2513247686
JukkaLhttps://github.com/JukkaL
on Aug 7, 2019https://github.com/python/mypy/issues/7239#event-2540867532
Add beginnings of error code support (#7267)https://github.com/python/mypy/commit/bf47c6506eeb35d22b3c43239527d4b60f5042eb
#7267https://github.com/python/mypy/pull/7267
bf47c65https://github.com/python/mypy/commit/bf47c6506eeb35d22b3c43239527d4b60f5042eb
sigmavirus24https://github.com/sigmavirus24
on Aug 12, 2019https://github.com/python/mypy/issues/7239#event-2550110265
In PEP 484 type comments, allow text after "# type: ignore" (#455)https://github.com/PyCQA/pyflakes/commit/fa92556ca04214fbe292b3d007b34059e8490b5e
#455https://github.com/PyCQA/pyflakes/pull/455
fa92556https://github.com/PyCQA/pyflakes/commit/fa92556ca04214fbe292b3d007b34059e8490b5e
https://github.com/JukkaL
JukkaLhttps://github.com/JukkaL
on Aug 14, 2019https://github.com/python/mypy/issues/7239#issuecomment-521309093
#7334https://github.com/python/mypy/pull/7334
JukkaLhttps://github.com/JukkaL
completedhttps://github.com/python/mypy/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Aug 14, 2019https://github.com/python/mypy/issues/7239#event-2557111718
https://github.com/kaste
kastehttps://github.com/kaste
on Aug 14, 2019https://github.com/python/mypy/issues/7239#issuecomment-521355388
https://github.com/JukkaL
JukkaLhttps://github.com/JukkaL
on Aug 15, 2019https://github.com/python/mypy/issues/7239#issuecomment-521535450
@kastehttps://github.com/kaste
https://github.com/Michael0x2a
Michael0x2ahttps://github.com/Michael0x2a
on Aug 15, 2019https://github.com/python/mypy/issues/7239#issuecomment-521646078
https://github.com/kaste
kastehttps://github.com/kaste
on Aug 15, 2019https://github.com/python/mypy/issues/7239#issuecomment-521671172
https://github.com/anentropic
anentropichttps://github.com/anentropic
on Feb 2, 2020https://github.com/python/mypy/issues/7239#issuecomment-581131921
https://github.com/JukkaL
JukkaLhttps://github.com/JukkaL
on Feb 3, 2020https://github.com/python/mypy/issues/7239#issuecomment-581536494
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/mypy/issues/7239
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/mypy/issues/7239
JukkaLhttps://github.com/JukkaL
featurehttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22feature%22
priority-0-highhttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22priority-0-high%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.