在Windows 7 / Python 3.2.5(pip install pylint)下安装Pylint 1.5.4后,尝试调用时出现以下异常:
b:\Sandbox\PyLoad>pylint PyLoad.py
Traceback (most recent call last):
File "c:\python32\lib\site-packages\astroid\builder.py", line 172, in _data_build
node = _parse(data + '\n')
File "c:\python32\lib\site-packages\astroid\builder.py", line 40, in _parse
return compile(string, "<string>", 'exec', _ast.PyCF_ONLY_AST)
File "<string>", line 12
return u''
^
SyntaxError: invalid syntax
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\python32\lib\runpy.py", line 161, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "c:\python32\lib\runpy.py", line 74, in _run_code
exec(code, run_globals)
File "C:\Python32\Scripts\pylint.exe\__main__.py", line 9, in <module>
File "c:\python32\lib\site-packages\pylint\__init__.py", line 22, in run_pylint
from pylint.lint import Run
File "c:\python32\lib\site-packages\pylint\lint.py", line 44, in <module>
import astroid
File "c:\python32\lib\site-packages\astroid\__init__.py", line 136, in <module>
__import__(module[:-3])
File "c:\python32\lib\site-packages\astroid\brain\brain_builtin_inference.py", line 76, in <module>
'str': partial(_extend_str, rvalue="''")})
File "c:\python32\lib\site-packages\astroid\brain\brain_builtin_inference.py", line 72, in extend_builtins
transform(builtin_ast[class_name])
File "c:\python32\lib\site-packages\astroid\brain\brain_builtin_inference.py", line 63, in _extend_str
fake = AstroidBuilder(MANAGER).string_build(code)['whatever']
File "c:\python32\lib\site-packages\astroid\builder.py", line 146, in string_build
module = self._data_build(data, modname, path)
File "c:\python32\lib\site-packages\astroid\builder.py", line 174, in _data_build
raise exceptions.AstroidBuildingException(exc)
astroid.exceptions.AstroidBuildingException: invalid syntax (<string>, line 12)
看起来有些东西试图使用Python 2语法返回一个unicode字符串,但这是Python 3。
在astroid的builder.py中,使用字符串调用_data_build:
class whatever(object):
def join(self, iterable):
return b''
def replace(self, old, new, count=None):
return b''
def format(self, *args, **kwargs):
return b''
def encode(self, encoding='ascii', errors=None):
return ''
def decode(self, encoding='ascii', errors=None):
return u''
.
.
.
我认为 return u''导致问题。
有人看过这个,并有解决方案吗?