Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Unified Diff: third_party/logilab/astroid/builder.py

Issue 753543006: pylint: upgrade to 1.4.0 (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/logilab/astroid/brain/py2stdlib.py ('k') | third_party/logilab/astroid/inference.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/logilab/astroid/builder.py
diff --git a/third_party/logilab/astroid/builder.py b/third_party/logilab/astroid/builder.py
index 692016a3677f19f617f5c0eb5124279a1a50bfda..1fe7a36d42290f70fb31b0f5d28219fa71bb8fe1 100644
--- a/third_party/logilab/astroid/builder.py
+++ b/third_party/logilab/astroid/builder.py
@@ -44,7 +44,7 @@ if sys.version_info >= (3, 0):
def open_source_file(filename):
with open(filename, 'rb') as byte_stream:
encoding = detect_encoding(byte_stream.readline)[0]
- stream = open(filename, 'rU', encoding=encoding)
+ stream = open(filename, 'r', newline=None, encoding=encoding)
try:
data = stream.read()
except UnicodeError: # wrong encodingg
@@ -115,23 +115,24 @@ class AstroidBuilder(InspectBuilder):
path is expected to be a python source file
"""
try:
- _, encoding, data = open_source_file(path)
- except IOError, exc:
+ stream, encoding, data = open_source_file(path)
+ except IOError as exc:
msg = 'Unable to load file %r (%s)' % (path, exc)
raise AstroidBuildingException(msg)
- except SyntaxError, exc: # py3k encoding specification error
+ except SyntaxError as exc: # py3k encoding specification error
raise AstroidBuildingException(exc)
- except LookupError, exc: # unknown encoding
+ except LookupError as exc: # unknown encoding
raise AstroidBuildingException(exc)
- # get module name if necessary
- if modname is None:
- try:
- modname = '.'.join(modpath_from_file(path))
- except ImportError:
- modname = splitext(basename(path))[0]
- # build astroid representation
- module = self._data_build(data, modname, path)
- return self._post_build(module, encoding)
+ with stream:
+ # get module name if necessary
+ if modname is None:
+ try:
+ modname = '.'.join(modpath_from_file(path))
+ except ImportError:
+ modname = splitext(basename(path))[0]
+ # build astroid representation
+ module = self._data_build(data, modname, path)
+ return self._post_build(module, encoding)
def string_build(self, data, modname='', path=None):
"""build astroid from source code string and return rebuilded astroid"""
@@ -159,7 +160,10 @@ class AstroidBuilder(InspectBuilder):
def _data_build(self, data, modname, path):
"""build tree node from data and add some informations"""
# this method could be wrapped with a pickle/cache function
- node = parse(data + '\n')
+ try:
+ node = parse(data + '\n')
+ except TypeError as exc:
+ raise AstroidBuildingException(exc)
if path is not None:
node_file = abspath(path)
else:
@@ -170,8 +174,7 @@ class AstroidBuilder(InspectBuilder):
else:
package = path and path.find('__init__.py') > -1 or False
rebuilder = TreeRebuilder(self._manager)
- module = rebuilder.visit_module(node, modname, package)
- module.file = module.path = node_file
+ module = rebuilder.visit_module(node, modname, node_file, package)
module._from_nodes = rebuilder._from_nodes
module._delayed_assattr = rebuilder._delayed_assattr
return module
« no previous file with comments | « third_party/logilab/astroid/brain/py2stdlib.py ('k') | third_party/logilab/astroid/inference.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698