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

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

Closed
nedbat opened this issue Aug 27, 2015 · 3 comments
Closed
Labels
bug Something isn't working report

Comments

@nedbat
Copy link
Owner

nedbat commented Aug 27, 2015

Originally reported by Ben Webb (Bitbucket: benmwebb, GitHub: benmwebb)


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:

#!shell

  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.


@nedbat
Copy link
Owner Author

nedbat commented Aug 27, 2015

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?

@nedbat
Copy link
Owner Author

nedbat commented Aug 27, 2015

Original comment by Ben Webb (Bitbucket: benmwebb, GitHub: benmwebb)


Actually it turns out to be pretty easy to trigger:

#!shell
$ 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.

@nedbat
Copy link
Owner Author

nedbat commented Aug 28, 2015

This is fixed in ad8bd671ec4f (bb).

@nedbat nedbat closed this as completed Aug 28, 2015
@nedbat nedbat added major bug Something isn't working report labels Jun 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working report
Projects
None yet
Development

No branches or pull requests

1 participant