Skip to content

--enable-error-code code does not enable some error codes, yet neither are they reported as an invalid error codes #19604

Open

Description

@wyattscarpenter

In my understanding, --enable-error-code unreachable should have the same effect as --warn-unreachable. But, instead, it seems to have no effect, and doesn't even produce an error.

$uvx mypy -c "if False: print('hello')"
Success: no issues found in 1 source file

$uvx mypy -c "if False: print('hello')" --warn-unreachable
<string>:1: error: Statement is unreachable  [unreachable]
Found 1 error in 1 file (checked 1 source file)

$uvx mypy -c "if False: print('hello')" --enable-error-code unreachable
Success: no issues found in 1 source file

$uvx mypy -c "if False: print('hello')" --enable-error-code unreachable --warn-unreachable
<string>:1: error: Statement is unreachable  [unreachable]
Found 1 error in 1 file (checked 1 source file)

$uvx mypy -c "if False: print('hello')" --enable-error-code funnyerrorcodenotreal
usage: mypy [-h] [-v] [-V] [more options; see below]
            [-m MODULE] [-p PACKAGE] [-c PROGRAM_TEXT] [files ...]
mypy: error: Invalid error code(s): funnyerrorcodenotreal

Based on my testing, this seems to have been the case since 1.0.0 and maybe before, and thus is not a recent regression.

Activity

  1. changed the title [-]--enable-error-code unreachable does not enable unreachability analysis, yet neither is it reported as an invalid error code[/-] [+]`--enable-error-code unreachable` does not enable unreachability analysis, yet neither is it reported as an invalid error code (etc)[/+] on Aug 7, 2025
  2. wyattscarpenter commented on Aug 7, 2025

    @wyattscarpenter
    ContributorAuthor

    Oh, the same thing is true about --warn-redundant-casts. And, I suspect, all error codes and flags like this.

    $uvx mypy -c "from typing import cast; cast(int, 1)" --warn-redundant-casts
    <string>:1: error: Redundant cast to "int"  [redundant-cast]
    Found 1 error in 1 file (checked 1 source file)
    
    $uvx mypy -c "from typing import cast; cast(int, 1)" --enable-error-code redundant-cast
    Success: no issues found in 1 source file
    

    If they aren't going to have any effect there should be an error message. (But, really, they should just have an effect!)

  3. A5rocks commented on Aug 30, 2025

    @A5rocks
    Collaborator

    (But, really, they should just have an effect!)

    Yeah we probably should have the flags enable certain error codes and then solely check those. There are a few flags that meaningfully change mypy's behavior in a way that error codes don't, but that should be limited! (Stuff like strict-optional)

  4. changed the title [-]`--enable-error-code unreachable` does not enable unreachability analysis, yet neither is it reported as an invalid error code (etc)[/-] [+]`--enable-error-code code` does not enable some error codes, yet neither are they reported as an invalid error codes[/+] on Oct 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-configurationConfiguration files and flags

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions