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

TypeError: compile() expected string without null bytes #118

Open
adiroiban opened this issue Aug 6, 2016 · 2 comments
Open

TypeError: compile() expected string without null bytes #118

adiroiban opened this issue Aug 6, 2016 · 2 comments

Comments

@adiroiban
Copy link
Member

See https://travis-ci.org/twisted/twisted/jobs/148667038

this is produced if we run twistedchecker

we also got this errors in the past, is just that they were hidden among the many linter errors.

Traceback (most recent call last):
  File "/home/travis/build/twisted/twisted/build/txchecker-travis/lib/python2.7/site-packages/pylint/lint.py", line 586, in get_astng
    return MANAGER.astng_from_file(filepath, modname, source=True)
  File "/home/travis/build/twisted/twisted/build/txchecker-travis/lib/python2.7/site-packages/logilab/astng/manager.py", line 104, in astng_from_file
    return ASTNGBuilder(self).file_build(filepath, modname)
  File "/home/travis/build/twisted/twisted/build/txchecker-travis/lib/python2.7/site-packages/logilab/astng/builder.py", line 128, in file_build
    node = self.string_build(data, modname, path)
  File "/home/travis/build/twisted/twisted/build/txchecker-travis/lib/python2.7/site-packages/logilab/astng/builder.py", line 134, in string_build
    module = self._data_build(data, modname, path)
  File "/home/travis/build/twisted/twisted/build/txchecker-travis/lib/python2.7/site-packages/logilab/astng/builder.py", line 150, in _data_build
    node = parse(data + '\n')
  File "/home/travis/build/twisted/twisted/build/txchecker-travis/lib/python2.7/site-packages/logilab/astng/builder.py", line 39, in parse
    return compile(string, "<string>", 'exec', PyCF_ONLY_AST)
TypeError: compile() expected string without null bytes
Traceback (most recent call last):
  File "/home/travis/build/twisted/twisted/build/txchecker-travis/lib/python2.7/site-packages/pylint/lint.py", line 586, in get_astng
    return MANAGER.astng_from_file(filepath, modname, source=True)
  File "/home/travis/build/twisted/twisted/build/txchecker-travis/lib/python2.7/site-packages/logilab/astng/manager.py", line 104, in astng_from_file
    return ASTNGBuilder(self).file_build(filepath, modname)
  File "/home/travis/build/twisted/twisted/build/txchecker-travis/lib/python2.7/site-packages/logilab/astng/builder.py", line 128, in file_build
    node = self.string_build(data, modname, path)
  File "/home/travis/build/twisted/twisted/build/txchecker-travis/lib/python2.7/site-packages/logilab/astng/builder.py", line 134, in string_build
    module = self._data_build(data, modname, path)
  File "/home/travis/build/twisted/twisted/build/txchecker-travis/lib/python2.7/site-packages/logilab/astng/builder.py", line 150, in _data_build
    node = parse(data + '\n')
  File "/home/travis/build/twisted/twisted/build/txchecker-travis/lib/python2.7/site-packages/logilab/astng/builder.py", line 39, in parse
    return compile(string, "<string>", 'exec', PyCF_ONLY_AST)
TypeError: compile() expected string without null bytes
Traceback (most recent call last):
  File "/home/travis/build/twisted/twisted/build/txchecker-travis/lib/python2.7/site-packages/pylint/lint.py", line 586, in get_astng
    return MANAGER.astng_from_file(filepath, modname, source=True)
  File "/home/travis/build/twisted/twisted/build/txchecker-travis/lib/python2.7/site-packages/logilab/astng/manager.py", line 104, in astng_from_file
    return ASTNGBuilder(self).file_build(filepath, modname)
  File "/home/travis/build/twisted/twisted/build/txchecker-travis/lib/python2.7/site-packages/logilab/astng/builder.py", line 128, in file_build
    node = self.string_build(data, modname, path)
  File "/home/travis/build/twisted/twisted/build/txchecker-travis/lib/python2.7/site-packages/logilab/astng/builder.py", line 134, in string_build
    module = self._data_build(data, modname, path)
  File "/home/travis/build/twisted/twisted/build/txchecker-travis/lib/python2.7/site-packages/logilab/astng/builder.py", line 150, in _data_build
    node = parse(data + '\n')
  File "/home/travis/build/twisted/twisted/build/txchecker-travis/lib/python2.7/site-packages/logilab/astng/builder.py", line 39, in parse
    return compile(string, "<string>", 'exec', PyCF_ONLY_AST)
TypeError: compile() expected string without null bytes
@tomprince
Copy link

This is caused by

src/twisted/test/raiser.so
src/twisted/runner/portmap.so
src/twisted/python/_sendmsg.so

trying to be opened as python files.

This happens in two places, once in twistedchecker/core/exceptionfinder.py and once somewhere inside pylint.

@tomprince
Copy link

diff --git a/twistedchecker/core/exceptionfinder.py b/twistedchecker/core/exceptionfinder.py
index 1557cdb..b8cc0d3 100644
--- a/twistedchecker/core/exceptionfinder.py
+++ b/twistedchecker/core/exceptionfinder.py
@@ -73,7 +73,9 @@ def findAllExceptions(pathToCheck):
     """
     finder = PatternFinder()
     if os.path.isfile(pathToCheck):
-        findPatternsInFile(open(pathToCheck).read(), finder)
+        _, extname = os.path.splitext(pathToCheck)
+        if extname == ".py":
+            findPatternsInFile(open(pathToCheck).read(), finder)
     else:
         for path, dirs, files in os.walk(pathToCheck):
             for file in files:

fixes the first error, uncovering the second. I'm not sure if the second can be addressed without changing pylint.

Julian added a commit to Julian/twisted that referenced this issue Nov 26, 2016
* trunk: (2745 commits)
  too many newlines as per review
  dev0 prefix
  ok maybe fix twistedchecker for realises?
  fix twistedchecker
  topfile
  make the test pass
  add tox minversion because of `extras` usage
  failing test
  topfile
  Explicitly ignore extension modules to work around twisted/twistedchecker#118.
  twistedchecker
  defer acquisition of the threadpool
  forward and backward compatibility
  twistedchecker
  distinct names since these need to live on the same object
  compatibility layer
  socktype
  socket types
  no, Nones are bad
  None first
  less code more data
  fewer lines
  hoist constant
  tests & fix for various AF_ types
  twistedchecker clean
  vws
  pacify twistedchecker
  docstring adjustment
  without that class, it should pass
  misc file for dev process change
  and now it should fail
  something that will _really_ fail diff-cover
  deleted lines won't warn
  it's not failing anyway
  be consistent about naming
  This should cause a new twistedchecker error, but it doesn't.
  address family selection
  quote of the release
  final newsfiles
  Revert "newsfiles"
  versions
  Remove unused import
  Move ConchOptions parsing tests to test_default
  Remove unused import
  Move ConchOptions parsing tests to test_default
  Modules used by tkconch on Python 3 should be removed from here
  Fix test on Python 3
  Fix the name of the topfile for twisted#3746.
  Update topfile.
  Test the default timeout.
  ...
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

No branches or pull requests

2 participants