hasher.update fails with TypeError: 'NoneType' object is not iterable

Issue #403 resolved
Ben Webb
created an issue

Let me know if you need a way to reproduce this and I'll see if I can boil it down to a simple example - but right now this is happening for our (pretty large) project.

This is on an x86_64 Fedora 22 box with the Fedora package, under Python 3 (the RPM claims to be python3-coverage-4.0-0.10.b1.fc22.x86_64). Partial stacktrace:

  File "/usr/lib64/python3.4/site-packages/coverage/control.py", line 1010, in html_report
    return reporter.report(morfs)
  File "/usr/lib64/python3.4/site-packages/coverage/html.py", line 124, in report   
    self.report_files(self.html_file, morfs, self.config.html_dir)
  File "/usr/lib64/python3.4/site-packages/coverage/report.py", line 83, in report_files
    report_fn(fr, self.coverage._analyze(fr))
  File "/usr/lib64/python3.4/site-packages/coverage/html.py", line 169, in html_file
    this_hash = self.file_hash(source.encode('utf-8'), fr)
  File "/usr/lib64/python3.4/site-packages/coverage/html.py", line 160, in file_hash
    self.coverage.data.add_to_hash(fr.filename, m)
  File "/usr/lib64/python3.4/site-packages/coverage/data.py", line 535, in add_to_hash
    hasher.update(sorted(self.arcs(filename)))
TypeError: 'NoneType' object is not iterable

This appears to occur because arcs() is returning None for at least one of the files in my project. The documentation for arcs() says that None is an acceptable return value...

Things work normally again for me if I modify the add_to_hash() function to check for a None return value, and if so, skip the hasher update.

Comments (4)

  1. Ned Batchelder repo owner

    Hmm, interesting! If you could figure out which file is causing the problem, and just share that file with me, that could be very helpful. And perhaps your .coverage data file?

  2. Ben Webb reporter

    Actually it turns out to be pretty easy to trigger:

    $ cat <<END > report.py
    import coverage
    cov = coverage.coverage(data_file='.coverage')
    cov.load()
    cov.html_report(morfs=['bar.py'], directory='htmlcov')
    END
    $ touch foo.py bar.py
    $ coverage run foo.py
    $ python report.py
    Traceback (most recent call last):
      File "report.py", line 4, in <module>
        cov.html_report(morfs=['bar.py'], directory='htmlcov')
      File "/usr/lib64/python3.4/site-packages/coverage/control.py", line 1010, in html_report
        return reporter.report(morfs)
      File "/usr/lib64/python3.4/site-packages/coverage/html.py", line 124, in report
        self.report_files(self.html_file, morfs, self.config.html_dir)
      File "/usr/lib64/python3.4/site-packages/coverage/report.py", line 83, in report_files
        report_fn(fr, self.coverage._analyze(fr))
      File "/usr/lib64/python3.4/site-packages/coverage/html.py", line 169, in html_file
        this_hash = self.file_hash(source.encode('utf-8'), fr)
      File "/usr/lib64/python3.4/site-packages/coverage/html.py", line 160, in file_hash
        self.coverage.data.add_to_hash(fr.filename, m)
      File "/usr/lib64/python3.4/site-packages/coverage/data.py", line 534, in add_to_hash
        hasher.update(sorted(self.lines(filename)))
    TypeError: 'NoneType' object is not iterable
    

    Of course this is because I'm specifically asking it to report on a file that wasn't covered by my test suite. (This suggests something is very wrong in my build system, but that's for me to fix!) I would expect a more informative error message in this case.

  3. Log in to comment