summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--astroid/as_string.py8
-rw-r--r--astroid/builder.py43
-rw-r--r--astroid/tests/unittest_regrtest.py11
-rw-r--r--astroid/tests/unittest_scoped_nodes.py1
4 files changed, 13 insertions, 50 deletions
diff --git a/astroid/as_string.py b/astroid/as_string.py
index 85afdc30..4cec2417 100644
--- a/astroid/as_string.py
+++ b/astroid/as_string.py
@@ -15,8 +15,6 @@
"""
import sys
-import six
-
# pylint: disable=unused-argument
@@ -243,12 +241,10 @@ class AsStringVisitor(object):
"""return an astroid.Function node as string"""
decorate = node.decorators.accept(self) if node.decorators else ''
docs = '\n%s"""%s"""' % (self.indent, node.doc) if node.doc else ''
- return_annotation = ''
- if six.PY3 and node.returns:
+ trailer = ':'
+ if node.returns:
return_annotation = '->' + node.returns.as_string()
trailer = return_annotation + ":"
- else:
- trailer = ":"
def_format = "\n%sdef %s(%s)%s%s\n%s"
return def_format % (decorate, node.name,
node.args.accept(self),
diff --git a/astroid/builder.py b/astroid/builder.py
index 433bd848..dec83674 100644
--- a/astroid/builder.py
+++ b/astroid/builder.py
@@ -12,10 +12,9 @@ The builder is not thread safe and can't be used to parse different sources
at the same time.
"""
-import re
import os
-import sys
import textwrap
+from tokenize import detect_encoding
from astroid._ast import _parse
from astroid import bases
@@ -36,41 +35,15 @@ _TRANSIENT_FUNCTION = '__'
# when calling extract_node.
_STATEMENT_SELECTOR = '#@'
-
-if sys.version_info >= (3, 0):
- from tokenize import detect_encoding
-
- def open_source_file(filename):
- with open(filename, 'rb') as byte_stream:
- encoding = detect_encoding(byte_stream.readline)[0]
- stream = open(filename, 'r', newline=None, encoding=encoding)
- data = stream.read()
- return stream, encoding, data
-
-else:
- _ENCODING_RGX = re.compile(r"\s*#+.*coding[:=]\s*([-\w.]+)")
-
- def _guess_encoding(string):
- """get encoding from a python file as string or return None if not found"""
- # check for UTF-8 byte-order mark
- if string.startswith('\xef\xbb\xbf'):
- return 'UTF-8'
- for line in string.split('\n', 2)[:2]:
- # check for encoding declaration
- match = _ENCODING_RGX.match(line)
- if match is not None:
- return match.group(1)
- return None
-
- def open_source_file(filename):
- """get data for parsing a file"""
- stream = open(filename, 'U')
- data = stream.read()
- encoding = _guess_encoding(data)
- return stream, encoding, data
+MANAGER = manager.AstroidManager()
-MANAGER = manager.AstroidManager()
+def open_source_file(filename):
+ with open(filename, 'rb') as byte_stream:
+ encoding = detect_encoding(byte_stream.readline)[0]
+ stream = open(filename, 'r', newline=None, encoding=encoding)
+ data = stream.read()
+ return stream, encoding, data
def _can_assign_attr(node, attrname):
diff --git a/astroid/tests/unittest_regrtest.py b/astroid/tests/unittest_regrtest.py
index c6d37031..c9062deb 100644
--- a/astroid/tests/unittest_regrtest.py
+++ b/astroid/tests/unittest_regrtest.py
@@ -9,8 +9,6 @@ import sys
import unittest
import textwrap
-import six
-
from astroid import MANAGER, Instance, nodes
from astroid.bases import BUILTINS
from astroid.builder import AstroidBuilder, extract_node
@@ -225,12 +223,9 @@ def test():
pass
""")
ancestors = list(node.ancestors())
- if six.PY3:
- self.assertEqual(len(ancestors), 1)
- self.assertEqual(ancestors[0].qname(),
- "{}.object".format(BUILTINS))
- else:
- self.assertEqual(len(ancestors), 0)
+ self.assertEqual(len(ancestors), 1)
+ self.assertEqual(ancestors[0].qname(),
+ "{}.object".format(BUILTINS))
def test_ancestors_missing_from_function(self):
# Test for https://www.logilab.org/ticket/122793
diff --git a/astroid/tests/unittest_scoped_nodes.py b/astroid/tests/unittest_scoped_nodes.py
index c22e0246..36c4155b 100644
--- a/astroid/tests/unittest_scoped_nodes.py
+++ b/astroid/tests/unittest_scoped_nodes.py
@@ -31,7 +31,6 @@ from astroid.bases import (
BUILTINS, Instance,
BoundMethod, UnboundMethod, Generator
)
-from astroid import __pkginfo__
from astroid import test_utils
from astroid.tests import resources