JulianEberius / SublimePythonIDE

ST3 only: A rewrite of SublimeRope for ST3, uses the Rope library to add python completions and refactoring to ST3
GNU General Public License v2.0
267 stars 38 forks source link

Pyflakes out of date; breaks on Python 3.6 syntax with Python 3.6 interpreter #91

Open autumnjolitz opened 7 years ago

autumnjolitz commented 7 years ago

I've a project config of:

{
    "folders":
    [
        {
            "path": "."
        }
    ],
    "settings": {
        "python_interpreter": "/Users/BenJolitz/.virtualenvs/cpython36/bin/python3.6",
    }
}

When I remove python_interpreter, the linter detects numerous issues like bad spacing, missing vars, etc,. Here is a sample where it should whine:

def bad():
    del a
    a.ax=1,  # <-- should whine about spacing at a minimum
    foo.bar.x
    foo(a)

When python_interpreter is set to Python 3, it no longer complains. I'm a bit uncertain how to proceed as I depend on the linter keeping me honest. For now, I add in things like 1=1 to provoke the linter to do its job.

autumnjolitz commented 7 years ago

After adding this to server.py:

root = logging.getLogger()
root.setLevel(logging.DEBUG)

ch = logging.FileHandler('/tmp/sublimepython.log')
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
root.addHandler(ch)

I was able to modify check_syntax to:

def check_syntax(self, code, encoding, lint_settings, filename):
        '''The linting mixin does not use the project_for machinery,
        but uses the linters directy.'''
        try:
            codes = do_linting(lint_settings, code, encoding, filename)
        except Exception:
            logging.exception('wtf')
            import traceback
            sys.stderr.write(traceback.format_exc())

Which revealed:

Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xmlrpc/server.py", line 392, in _dispatch
    func = self.funcs[method]
KeyError: 'check_syntax'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/Users/BenJolitz/Library/Application Support/Sublime Text 3/Packages/SublimePythonIDE/server/server.py", line 335, in check_syntax
    codes = do_linting(lint_settings, code, encoding, filename)
  File "/Users/BenJolitz/Library/Application Support/Sublime Text 3/Packages/SublimePythonIDE/server/linter.py", line 123, in do_linting
    errors.extend(pyflakes_check(code, encoding, filename, pyflakes_ignore))
  File "/Users/BenJolitz/Library/Application Support/Sublime Text 3/Packages/SublimePythonIDE/server/linter.py", line 44, in pyflakes_check
    w = pyflakes.Checker(tree, filename, builtins=ignore)
  File "/Users/BenJolitz/Library/Application Support/Sublime Text 3/Packages/SublimePythonIDE/server/../../SublimePythonIDE/pyflakes/checker.py", line 295, in __init__
    self.runDeferred(self._deferredFunctions)
  File "/Users/BenJolitz/Library/Application Support/Sublime Text 3/Packages/SublimePythonIDE/server/../../SublimePythonIDE/pyflakes/checker.py", line 332, in runDeferred
    handler()
  File "/Users/BenJolitz/Library/Application Support/Sublime Text 3/Packages/SublimePythonIDE/server/../../SublimePythonIDE/pyflakes/checker.py", line 823, in runFunction
    self.handleNode(stmt, node)
  File "/Users/BenJolitz/Library/Application Support/Sublime Text 3/Packages/SublimePythonIDE/server/../../SublimePythonIDE/pyflakes/checker.py", line 609, in handleNode
    handler(node)
  File "/Users/BenJolitz/Library/Application Support/Sublime Text 3/Packages/SublimePythonIDE/server/../../SublimePythonIDE/pyflakes/checker.py", line 567, in handleChildren
    self.handleNode(node, tree)
  File "/Users/BenJolitz/Library/Application Support/Sublime Text 3/Packages/SublimePythonIDE/server/../../SublimePythonIDE/pyflakes/checker.py", line 609, in handleNode
    handler(node)
  File "/Users/BenJolitz/Library/Application Support/Sublime Text 3/Packages/SublimePythonIDE/server/../../SublimePythonIDE/pyflakes/checker.py", line 916, in TRY
    self.handleChildren(node, omit='body')
  File "/Users/BenJolitz/Library/Application Support/Sublime Text 3/Packages/SublimePythonIDE/server/../../SublimePythonIDE/pyflakes/checker.py", line 567, in handleChildren
    self.handleNode(node, tree)
  File "/Users/BenJolitz/Library/Application Support/Sublime Text 3/Packages/SublimePythonIDE/server/../../SublimePythonIDE/pyflakes/checker.py", line 609, in handleNode
    handler(node)
  File "/Users/BenJolitz/Library/Application Support/Sublime Text 3/Packages/SublimePythonIDE/server/../../SublimePythonIDE/pyflakes/checker.py", line 925, in EXCEPTHANDLER
    self.handleChildren(node)
  File "/Users/BenJolitz/Library/Application Support/Sublime Text 3/Packages/SublimePythonIDE/server/../../SublimePythonIDE/pyflakes/checker.py", line 567, in handleChildren
    self.handleNode(node, tree)
  File "/Users/BenJolitz/Library/Application Support/Sublime Text 3/Packages/SublimePythonIDE/server/../../SublimePythonIDE/pyflakes/checker.py", line 609, in handleNode
    handler(node)
  File "/Users/BenJolitz/Library/Application Support/Sublime Text 3/Packages/SublimePythonIDE/server/../../SublimePythonIDE/pyflakes/checker.py", line 567, in handleChildren
    self.handleNode(node, tree)
  File "/Users/BenJolitz/Library/Application Support/Sublime Text 3/Packages/SublimePythonIDE/server/../../SublimePythonIDE/pyflakes/checker.py", line 609, in handleNode
    handler(node)
  File "/Users/BenJolitz/Library/Application Support/Sublime Text 3/Packages/SublimePythonIDE/server/../../SublimePythonIDE/pyflakes/checker.py", line 567, in handleChildren
    self.handleNode(node, tree)
  File "/Users/BenJolitz/Library/Application Support/Sublime Text 3/Packages/SublimePythonIDE/server/../../SublimePythonIDE/pyflakes/checker.py", line 608, in handleNode
    handler = self.getNodeHandler(node.__class__)
  File "/Users/BenJolitz/Library/Application Support/Sublime Text 3/Packages/SublimePythonIDE/server/../../SublimePythonIDE/pyflakes/checker.py", line 462, in getNodeHandler
    self._nodeHandlers[node_class] = handler = getattr(self, nodeType)
AttributeError: 'Checker' object has no attribute 'JOINEDSTR'

Looks like pyflakes is out of date, as they've fixed that via https://github.com/PyCQA/pyflakes/pull/80


Aaand the issue is solved by copying pyflakes/pyflakes HEAD into SublimePythonIDE/pyflakes/ . And confirmed.

Pyflakes in this project is out of date and does not support Python3.6 syntax properly. By using an older pyflakes version, SublimePythonIDE breaks linting (silently) for Python 3 interpreters.