Skip to content
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

mypy --any-exprs-report depends on formatting #18405

Open
SoloJacobs opened this issue Jan 1, 2025 · 0 comments
Open

mypy --any-exprs-report depends on formatting #18405

SoloJacobs opened this issue Jan 1, 2025 · 0 comments
Labels
bug mypy got something wrong

Comments

@SoloJacobs
Copy link

Bug Report

The report any-exprs.txt generated by mypy --any-exprs-report changes its output, even if the AST has not changed in any way.

To Reproduce

This is a minimal example:

Error = (
    int
    | int
)

mypy reports

 Name   Anys   Exprs   Coverage
-------------------------------
    t      2       4     50.00%
-------------------------------
Total      2       4     50.00%

On the other hand, this example produces no errors

OK = int | int

Again the table, for completeness.

 Name   Anys   Exprs   Coverage
-------------------------------
    s      0       2    100.00%
-------------------------------
Total      0       2    100.00%

The underlying reason is that mypy counts expressions set as TYPE_UNANALYZED as Anys expression. This is very surprising to me. The specific expression is assigned TYPE_UNANALYZED in StatisticsVisitor.type.

Expected Behavior

The invocation mypy --any-exprs-report matches the number of errors encountered by running mypy --disallow-any-exprs. Or at the very least clear up the documentation:

Causes mypy to generate a text file report documenting how many
    expressions of type ``Any`` are present within your codebase.

Your Environment

I don't think this matters, but:

  • Mypy version used:
    mypy 1.14.0 (compiled: yes)
    mypy 1.15.0+dev.d79d89e3ff31ed67a41b0663da9ec8e037d41fa0 (compiled: no)
  • Mypy command-line flags: --any-exprs-report
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.12.1
@SoloJacobs SoloJacobs added the bug mypy got something wrong label Jan 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

1 participant