Ticket #877 (closed defect: fixed)

Opened 3 years ago

Last modified 13 months ago

[with patch, positive review] "sage -coverage" should not care about functions which are local to other functions/methods

Reported by: cwitty Owned by: jhpalmieri
Priority: minor Milestone: sage-4.1.1
Component: documentation Keywords:
Cc: Author(s): John Palmieri
Report Upstream: Reviewer(s): William Stein, Harald Schilly
Merged in: Sage 4.1.1.alpha1 Work issues:

Description

Currently, if you have something like:

def foo():
    def bar():
        pass
    pass

then "sage -coverage" will complain that bar() has no docstring or doctests. However, such functions cannot be (directly) doctested, so that warning is invalid. In my opinion, bar() should not be required to have a docstring either.

Attachments

trac_877-scripts-coverage.patch Download (2.3 KB) - added by jhpalmieri 13 months ago.
apply to scripts repository
trac_877-scripts-coverage2.patch Download (2.6 KB) - added by jhpalmieri 13 months ago.
use this version instead

Change History

Changed 2 years ago by mhansen

To get around this, I took my local function/method and made it a regular one. I then used functools.partial to use it. This allowed my function to be tested like every other one. In the few cases where I had to do this, I ended up liking the functools version better.

Changed 19 months ago by zimmerma

#4323 is a duplicate of that ticket.

Changed 13 months ago by jhpalmieri

  • owner changed from tba to jhpalmieri
  • status changed from new to assigned
  • summary changed from "sage -coverage" should not care about functions which are local to other functions/methods to [with patch, needs review] "sage -coverage" should not care about functions which are local to other functions/methods
  • author set to John Palmieri

Here is a patch for this. With sage-4.1.1.alpha0, it increases overall coverage from 77.9% to 78.5%.

To test: I know that the files steenrod_algebra_element.py and structure/factorization.py have such nested functions, so try 'sage -coverage' on these files, before and after patching.

Changed 13 months ago by jhpalmieri

apply to scripts repository

Changed 13 months ago by jhpalmieri

(Maybe it only goes from 78.0% to 78.5%.)

Changed 13 months ago by was

  • summary changed from [with patch, needs review] "sage -coverage" should not care about functions which are local to other functions/methods to [with patch, positive review] "sage -coverage" should not care about functions which are local to other functions/methods

Looks good to me:

BEFORE:

< Overall weighted coverage score:  77.8%
< Total number of functions:  22395

AFTER

> Overall weighted coverage score:  78.3%
> Total number of functions:  22207

The code looks fine and it works fine, so far as I can tell.

Changed 13 months ago by schilly

quick note just from looking at the patch: i makes more sense to move the re.compile statement *before* the while True: loop. It's purpose is to speed up the regex searches and shouldn't be compiled in every loop! just exchange line 20 and 21 in the merged file.

Changed 13 months ago by jhpalmieri

use this version instead

Changed 13 months ago by jhpalmieri

trac_877-scripts-coverage2.patch interchanges the lines that schilly mentions. It also moves another re.compile statement earlier. It also stores the list of nested functions in the list "closures", for possible future use.

Changed 13 months ago by mvngu

  • status changed from assigned to closed
  • reviewer set to William Stein, Harald Schilly
  • resolution set to fixed
  • merged set to Sage 4.1.1.alpha1

This is what I observe regarding John's patch. In Sage 4.1 without the patch trac_877-scripts-coverage2.patch, we have

Overall weighted coverage score:  77.8%
Total number of functions:  22398

Applying that patch to Sage 4.1:

Overall weighted coverage score:  78.3%
Total number of functions:  22210

If I understand John's patch correctly, it doesn't count functions which are local to other functions/methods. This accounts for the reduced number of total functions after applying the patch. Moving on to Sage 4.1.1.alpha0 without the patch:

Overall weighted coverage score:  78.0%
Total number of functions:  22497

And with the patch:

Overall weighted coverage score:  78.5%
Total number of functions:  22308

Here is the coverage after applying the patch to my merge tree:

Overall weighted coverage score:  78.6%
Total number of functions:  22317


Merged trac_877-scripts-coverage2.patch in the scripts repository.

Note: See TracTickets for help on using tickets.