KEMBAR78
Increase the precision of the summary in `trace` module · Issue #112192 · python/cpython · GitHub
Skip to content

Increase the precision of the summary in trace module #112192

@gaogaotiantian

Description

@gaogaotiantian

Feature or enhancement

Proposal:

With the current trace module, you'll have a summary like this if you enable summary

lines   cov%   module   (path)
  154    24%   _weakrefset   (/home/gaogaotiantian/programs/mycpython/Lib/_weakrefset.py)
 1293     0%   ast   (/home/gaogaotiantian/programs/mycpython/Lib/ast.py)
  160     5%   bz2   (/home/gaogaotiantian/programs/mycpython/Lib/bz2.py)
  133    39%   cProfile   (/home/gaogaotiantian/programs/mycpython/Lib/cProfile.py)
  903     7%   collections.__init__   (/home/gaogaotiantian/programs/mycpython/Lib/collections/__init__.py)

I propose to increase the precision of cov% to one decimal place so you'll have something like

lines    cov%   module   (path)
  154   24.7%   _weakrefset   (/home/gaogaotiantian/programs/mycpython/Lib/_weakrefset.py)
 1293    0.2%   ast   (/home/gaogaotiantian/programs/mycpython/Lib/ast.py)
  160    5.0%   bz2   (/home/gaogaotiantian/programs/mycpython/Lib/bz2.py)
  133   39.8%   cProfile   (/home/gaogaotiantian/programs/mycpython/Lib/cProfile.py)
  903    7.8%   collections.__init__   (/home/gaogaotiantian/programs/mycpython/Lib/collections/__init__.py)

This may seem a bit non-sense at the first glance, but it's related to a very practical question - how do we know our coverage improved after some new test cases? With integer percentage, we have a 1% resolution, which means we can't tell if there's a one line improvement if the file is larger than 100 lines. For a file that has 1000 lines, the resolution is 10 lines! It's not trivial!

By introducing only a single digit, we improved the resolution to 0.1%, which is arbitray I know. But, in practical, most Python modules have lines between 100 and 1000 lines.

Check a quick "wc -l Lib/*.py" result. Remember, this is without comments so the real line number is smaller 147 Lib/__future__.py 16 Lib/__hello__.py 108 Lib/_aix_support.py 1173 Lib/_collections_abc.py 251 Lib/_compat_pickle.py 162 Lib/_compression.py 396 Lib/_markupbase.py 335 Lib/_opcode_metadata.py 574 Lib/_osx_support.py 147 Lib/_py_abc.py 2649 Lib/_pydatetime.py 6425 Lib/_pydecimal.py 2683 Lib/_pyio.py 285 Lib/_pylong.py 103 Lib/_sitebuiltins.py 566 Lib/_strptime.py 242 Lib/_threading_local.py 205 Lib/_weakrefset.py 188 Lib/abc.py 17 Lib/antigravity.py 2656 Lib/argparse.py 1836 Lib/ast.py 584 Lib/base64.py 900 Lib/bdb.py 118 Lib/bisect.py 344 Lib/bz2.py 195 Lib/cProfile.py 796 Lib/calendar.py 400 Lib/cmd.py 371 Lib/code.py 1132 Lib/codecs.py 151 Lib/codeop.py 166 Lib/colorsys.py 469 Lib/compileall.py 1283 Lib/configparser.py 814 Lib/contextlib.py 4 Lib/contextvars.py 305 Lib/copy.py 217 Lib/copyreg.py 451 Lib/csv.py 1592 Lib/dataclasses.py 9 Lib/datetime.py 11 Lib/decimal.py 2056 Lib/difflib.py 933 Lib/dis.py 2856 Lib/doctest.py 2052 Lib/enum.py 313 Lib/filecmp.py 442 Lib/fileinput.py 192 Lib/fnmatch.py 988 Lib/fractions.py 959 Lib/ftplib.py 1026 Lib/functools.py 167 Lib/genericpath.py 215 Lib/getopt.py 185 Lib/getpass.py 657 Lib/gettext.py 311 Lib/glob.py 250 Lib/graphlib.py 694 Lib/gzip.py 253 Lib/hashlib.py 603 Lib/heapq.py 219 Lib/hmac.py 1632 Lib/imaplib.py 3451 Lib/inspect.py 99 Lib/io.py 2341 Lib/ipaddress.py 64 Lib/keyword.py 191 Lib/linecache.py 1742 Lib/locale.py 356 Lib/lzma.py 2198 Lib/mailbox.py 645 Lib/mimetypes.py 666 Lib/modulefinder.py 192 Lib/netrc.py 901 Lib/ntpath.py 81 Lib/nturl2path.py 418 Lib/numbers.py 112 Lib/opcode.py 467 Lib/operator.py 1681 Lib/optparse.py 1152 Lib/os.py 1637 Lib/pathlib.py 2236 Lib/pdb.py 1814 Lib/pickle.py 2890 Lib/pickletools.py 529 Lib/pkgutil.py 1357 Lib/platform.py 911 Lib/plistlib.py 466 Lib/poplib.py 581 Lib/posixpath.py 655 Lib/pprint.py 615 Lib/profile.py 778 Lib/pstats.py 211 Lib/pty.py 212 Lib/py_compile.py 314 Lib/pyclbr.py 2851 Lib/pydoc.py 326 Lib/queue.py 237 Lib/quopri.py 1000 Lib/random.py 194 Lib/reprlib.py 219 Lib/rlcompleter.py 318 Lib/runpy.py 167 Lib/sched.py 71 Lib/secrets.py 603 Lib/selectors.py 250 Lib/shelve.py 345 Lib/shlex.py 1581 Lib/shutil.py 92 Lib/signal.py 671 Lib/site.py 1109 Lib/smtplib.py 967 Lib/socket.py 858 Lib/socketserver.py 7 Lib/sre_compile.py 7 Lib/sre_constants.py 7 Lib/sre_parse.py 1507 Lib/ssl.py 201 Lib/stat.py 1480 Lib/statistics.py 309 Lib/string.py 272 Lib/stringprep.py 15 Lib/struct.py 2209 Lib/subprocess.py 374 Lib/symtable.py 340 Lib/tabnanny.py 2904 Lib/tarfile.py 925 Lib/tempfile.py 497 Lib/textwrap.py 28 Lib/this.py 1733 Lib/threading.py 381 Lib/timeit.py 140 Lib/token.py 545 Lib/tokenize.py 747 Lib/trace.py 1227 Lib/traceback.py 560 Lib/tracemalloc.py 76 Lib/tty.py 4176 Lib/turtle.py 341 Lib/types.py 3432 Lib/typing.py 793 Lib/uuid.py 595 Lib/warnings.py 663 Lib/wave.py 674 Lib/weakref.py 620 Lib/webbrowser.py 206 Lib/zipapp.py 724 Lib/zipimport.py

As we can obviously tell, most of the files have line numbers between 100 and 1000. Even for files that have more than 1000 lines, they are normally less than 3000 lines. Again, the "executable lines" are less because wc counts empty lines and comments.

So, 0.1% is arbitrary, but I think it's the sweet spot for coverage report - it's not too verbose, but it can almost always show coverage changes for common python modules.

But, this is not backward compatible right? Yes, it's not. However, the summary is mainly used for human to read, not for machines. So I don't think there are a lot of code relying on the output of the summary. I believe most of the users would be happier than disturbed by the new resolution.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    performancePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions