KEMBAR78
Add Any Expressions report by ilinum · Pull Request #3492 · python/mypy · GitHub
Skip to content

Conversation

ilinum
Copy link
Collaborator

@ilinum ilinum commented Jun 1, 2017

This report measures the number of expressions in a file that have type Any.

This is what the report looks like:

mypy$ mypy --any-exprs-report any-exprs-report mypy
mypy$ cat any-exprs-report/any-exprs.txt
Name                         Anys    Exprs    Coverage
------------------------------------------------------
mypy.__main__                   0        9     100.00%
mypy.api                        0       41     100.00%
mypy.applytype                  0      152     100.00%
mypy.binder                     2      682      99.71%
mypy.build                     18     4331      99.58%
mypy.checker                    6     7154      99.92%
mypy.checkexpr                  0     6689     100.00%
mypy.checkmember                0     1541     100.00%
mypy.checkstrformat            14      812      98.28%
mypy.constraints                0      975     100.00%
mypy.defaults                   0        8     100.00%
mypy.erasetype                  0      179     100.00%
mypy.errors                     0     1157     100.00%
mypy.expandtype                 0      296     100.00%
mypy.experiments                0        6     100.00%
mypy.exprtotype                 0      281     100.00%
mypy.fastparse                 98     3135      96.87%
mypy.fastparse2                72     2512      97.13%
mypy.fixup                      7      761      99.08%
mypy.funcplugins                0       91     100.00%
mypy.git                       46      257      82.10%
mypy.indirection                0      248     100.00%
mypy.infer                      0       41     100.00%
mypy.join                       0      988     100.00%
mypy.main                     105     1484      92.92%
mypy.maptype                    0      157     100.00%
mypy.meet                       0      863     100.00%
mypy.messages                   6     2660      99.77%
mypy.moduleinfo                 0       54     100.00%
mypy.myunit                    45      897      94.98%
mypy.myunit.__main__            5       10      50.00%
mypy.nodes                    124     4226      97.07%
mypy.options                    1      276      99.64%
mypy.parse                      0       32     100.00%
mypy.report                    14     1657      99.16%
mypy.sametypes                  0      328     100.00%
mypy.semanal                  108    12061      99.10%
mypy.server.astdiff             0      535     100.00%
mypy.server.astmerge            0      502     100.00%
mypy.server.aststrip            0      185     100.00%
mypy.server.deps                0      594     100.00%
mypy.server.subexpr             0      302     100.00%
mypy.server.target              0       42     100.00%
mypy.server.trigger             0        4     100.00%
mypy.server.update              0      819     100.00%
mypy.sharedparse                0       24     100.00%
mypy.solve                      0      107     100.00%
mypy.stats                      0      855     100.00%
mypy.strconv                   40     1706      97.66%
mypy.stubgen                   74     1843      95.98%
mypy.stubgenc                  18      547      96.71%
mypy.stubutil                   3      302      99.01%
mypy.subtypes                   0     1745     100.00%
mypy.test.config                0       27     100.00%
mypy.test.data                 54     1366      96.05%
mypy.test.helpers               1      771      99.87%
mypy.test.testargs              0       17     100.00%
mypy.test.testcheck             1      718      99.86%
mypy.test.testcmdline           6      217      97.24%
mypy.test.testdeps              0      123     100.00%
mypy.test.testdiff              0      135     100.00%
mypy.test.testextensions      248      360      31.11%
mypy.test.testfinegrained       1      238      99.58%
mypy.test.testgraph             0      169     100.00%
mypy.test.testinfer             0      357     100.00%
mypy.test.testmerge             1      503      99.80%
mypy.test.testmoduleinfo        0       26     100.00%
mypy.test.testparse             0      107     100.00%
mypy.test.testpythoneval       10      205      95.12%
mypy.test.testreports           1       50      98.00%
mypy.test.testsemanal           0      434     100.00%
mypy.test.testsolve             0      580     100.00%
mypy.test.teststubgen           0      382     100.00%
mypy.test.testsubtypes          0     1065     100.00%
mypy.test.testtransform         0      140     100.00%
mypy.test.testtypegen           0      311     100.00%
mypy.test.testtypes             0     4044     100.00%
mypy.traverser                  0      734     100.00%
mypy.treetransform              0     1720     100.00%
mypy.tvar_scope                 0      200     100.00%
mypy.typeanal                   0     1988     100.00%
mypy.typefixture                0      932     100.00%
mypy.types                    120     3723      96.78%
mypy.typevars                   0       44     100.00%
mypy.util                       8      201      96.02%
mypy.version                    0       31     100.00%
mypy.visitor                    0      424     100.00%
mypy.waiter                    61     1074      94.32%
------------------------------------------------------
Total                        1318    90579      98.54%

This report measures the number of expressions in a file that have type Any.
@gvanrossum
Copy link
Member

gvanrossum commented Jun 2, 2017 via email

If there's a cycle in function expansion, report filename and line number
@ilinum
Copy link
Collaborator Author

ilinum commented Jun 2, 2017

@gvanrossum yes, done!

That was code that was already there, so I didn't touch it. But it would be useful to have that, I agree.

Here is what the output looks like now:

mypy.nodes:224: ERROR: cycle in function expansion; skipping
mypy.types:25: ERROR: cycle in function expansion; skipping
mypy.fastparse:758: ERROR: cycle in function expansion; skipping
mypy.fastparse:763: ERROR: cycle in function expansion; skipping
mypy.fastparse2:753: ERROR: cycle in function expansion; skipping
mypy.fastparse2:758: ERROR: cycle in function expansion; skipping
mypy.server.aststrip:44: ERROR: cycle in function expansion; skipping
mypy.typeanal:335: ERROR: cycle in function expansion; skipping
mypy.semanal:293: ERROR: cycle in function expansion; skipping
mypy.semanal:429: ERROR: cycle in function expansion; skipping
mypy.semanal:556: ERROR: cycle in function expansion; skipping
mypy.semanal:630: ERROR: cycle in function expansion; skipping
mypy.semanal:637: ERROR: cycle in function expansion; skipping
mypy.checker:163: ERROR: cycle in function expansion; skipping
mypy.checker:195: ERROR: cycle in function expansion; skipping
mypy.checker:230: ERROR: cycle in function expansion; skipping
mypy.checker:548: ERROR: cycle in function expansion; skipping
mypy.checker:576: ERROR: cycle in function expansion; skipping
mypy.checker:1082: ERROR: cycle in function expansion; skipping
mypy.build:68: ERROR: cycle in function expansion; skipping
mypy.build:111: ERROR: cycle in function expansion; skipping

@gvanrossum
Copy link
Member

So much better!

@ddfisher ddfisher self-requested a review June 2, 2017 19:58
Copy link
Collaborator

@ddfisher ddfisher left a comment

Choose a reason for hiding this comment

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

Code-wise this looks good (with just a couple small questions around some magic formatting numbers), but I'm not sure it does what it says on the tin: it looks to me like this gives the percentage of lines that contain Any. This may be reasonable behavior, but the name would need to be changed.

Also, it doesn't have to happen in this PR, but further investigation is needed into the cycle in function expansion errors. Optimally, we'd understand the root cause and fix it.

mypy/report.py Outdated
# find the longest filename all files
name_width = max([len(file) for file in self.counts] + [len(file_column_name)])
# totals are the largest numbers in their column - no need to look at others
any_width = max(len(str(total_any)) + 3, len(any_column_name))
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the + 3 from here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the minimum distance between numbers in two columns.

Hopefully, this is more clear after the new commit.

mypy/report.py Outdated
# totals are the largest numbers in their column - no need to look at others
any_width = max(len(str(total_any)) + 3, len(any_column_name))
exprs_width = max(len(str(total_expr)) + 3, len(total_column_name))
header = '{:{name_width}} {:>{any_width}} {:>{total_width}} {:>11}'.format(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This 11 and the 10s below feel a little magical.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, this is some real magic numbers. Should be better now!

@ilinum
Copy link
Collaborator Author

ilinum commented Jun 6, 2017

@ddfisher Thanks for the review!

The new reporter reports types, not lines. It uses StatisticsVisitor, which visits every type recursively (for every expression, it calls, process node, which itself calls type, which records the number of any types)

As for cycle in function expansion, I opened: #3503.

Copy link
Collaborator

@ddfisher ddfisher left a comment

Choose a reason for hiding this comment

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

Ah, yep! You're right -- it does check exprs. Great!

This looks good to me! Thanks for fixing the nits I pointed out.

@ilinum ilinum merged commit e86c0dc into python:master Jun 7, 2017
@ilinum ilinum deleted the any-expr-report branch June 7, 2017 00:10
@ddfisher
Copy link
Collaborator

ddfisher commented Jun 7, 2017

🎉

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.

3 participants