Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add a flag --enable-all-error-codes, which enables all error codes #19048

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: master
Choose a base branch
from

Conversation

wyattscarpenter
Copy link
Contributor

@wyattscarpenter wyattscarpenter commented May 7, 2025

(edit: --enable-error-code all is now "spelled" --enable-all-error-codes, thanks to the feedback I received on this PR.)

This code change allows users to use --enable-error-code all to enable all error codes. This "fixes" #2376 (which was closed as not planned — but a decade of hindsight has, I think, revealed that the idea for a flag like this is more practical than it initially seemed). It also addresses a feature request that was mentioned in the course of discussing #18078 (it does not fix #18078, which is an issue about something else).

My main motivation to add this feature is that it's very easy to add and somewhat useful to me and others, who sometimes want to see what the effect of enabling all error codes is, whether we decide to check our code with that every time or just want to evaluate all of the codes at once to see which are worthwhile.

I don't think this PR closes further discussion on whether, eg, --strict should also enable every error code, which I also think should be true, but for other reasons; nor what flags should control what other error codes, which is also a fertile grounds for discussion. I conceptualize --enable-error-codes all as sort of a "low-level" command line option that does something simple to define (all), whereas other flags do something more ergonomic like give you some recommended set of error codes.

This code change seems like it should allow not just command line usage but also configuration file usage, but for some opaque reason (perhaps my machine configuration is just cursed?) this did not work for me (it resulted in an "invalid error code" error message). So it's documented as only a command line feature. (edit: this works fine, now)

The test for this feature spotchecks that --enable-error-code all enabled explicit-override and a couple other errors.

This comment has been minimized.

@wyattscarpenter wyattscarpenter marked this pull request as draft May 8, 2025 00:07

This comment has been minimized.

@wyattscarpenter
Copy link
Contributor Author

OK, I don't really understand the whole situation here with the stubs, but I guess I have to add @overload to a number of them. Whatever they're for.

This comment has been minimized.

This comment has been minimized.

1 similar comment

This comment has been minimized.

@wyattscarpenter wyattscarpenter marked this pull request as ready for review May 8, 2025 22:03
@A5rocks
Copy link
Collaborator

A5rocks commented May 9, 2025

IMO this is less discoverable than a flag (e.g. --all-checks) but maybe I'm wrong. I agree the basic idea makes sense though.

@sterliakov
Copy link
Collaborator

Agree with @A5rocks - there was a ticket for --all-checks or a similar flag that is a superset of --strict and enables all our optional codes, I don't think all error code is good. This also introduces a discrepancy: what should # type: ignore[all] do? Does it silence everything like a bare ignore? Is it an error to use such comment at all?

@wyattscarpenter
Copy link
Contributor Author

@sterliakov, yeah, all is only a frontend option — which I tried to communicate in the documentation — and doesn't do anything in a type: ignore (as far as I know). Have an issue number for that "--all-checks or similar"? I'm happy to close an issue. Possibly adapting this code.

Although, implementing this as a pseudo error code was pretty easy, which is why I did it. I also think it's a good interface for people already involved in enabling error codes — you just specify all!

@sterliakov
Copy link
Collaborator

That's an unprecedented behavior for error codes: any existing error code can be used in a suppression comment. I don't think introducing a "meta" error code that isn't usable in type: ignore[code] comments provides good UX - I'm moderately certain we'll receive a report "# type: ignore[all] doesn't suppress all diagnostics on its line!" within a month after releasing it.

I somehow can't find the issue for --all-checks, that might've been a discussion on some PR. I'll try harder tomorrow:) But there is a rejected #2376 proposing such.

@wyattscarpenter
Copy link
Contributor Author

@sterliakov Such a reporter should have the purpose of specifying error codes explained to them 🤭

Regardless, I'm a pragmatist about these things, and don't actually care much about the exact flag. While continuing to advocate for the PR in its current state (--enable-error-code all), I'll see if I can easily adapt it into --all-checks, if people like that better.

@sterliakov
Copy link
Collaborator

Also related (and closable by any implementation of this idea) #14143

@wyattscarpenter
Copy link
Contributor Author

True... I'll try to remember to update the documentation to mention this in the documentation of --strict as an alternative.

@sobolevn
Copy link
Member

yes, I agree that a new flag is better than all. But, I fully support the core idea.

@wyattscarpenter
Copy link
Contributor Author

--all-checks would be a good name for some possible flag, but on reflection I think it would be misleading for this one, because "checks" is a broader concept than "code". For example, this flag doesn't enable --strict-bytes, even though that's an additional check. So, I've called this flag --enable-all-error-codes.

@wyattscarpenter wyattscarpenter changed the title Add a pseudo error code, all, which enables all error codes Add a flag --enable-all-error-codes, which enables all error codes May 11, 2025
codes, including any that may be experimental, wrongheaded, or
contradictory.

Enabling all codes is not the same as enabling all checks that mypy could
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also mention that specifing both --enable-error-code and --enable-all-error-codes must be an error. It is either or.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess if I take your previous suggestion about how --disable-error-code should supersede, then one could use --enable-all-error-codes --disable-error-code x --enable-error-code x, which would be no more erroneous than using --disable-error-code x --enable-error-code x is already. 🤔

This comment has been minimized.

Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable --warn-unreachable in --strict in Mypy 2.0
4 participants