From d5ab86bbe2baf4a07d0f3fc00a8b6389ffd6d2d2 Mon Sep 17 00:00:00 2001 From: Claudiu Popa Date: Sat, 3 Jan 2015 23:38:45 +0200 Subject: .slots() can contain unicode strings on Python 2. --- ChangeLog | 2 ++ astroid/scoped_nodes.py | 3 ++- astroid/tests/unittest_scoped_nodes.py | 12 ++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index b9dfa5b6..64495a57 100644 --- a/ChangeLog +++ b/ChangeLog @@ -30,6 +30,8 @@ Change log for the astroid package (used to be astng) * Improve the detection for functions decorated with decorators which returns static or class methods. + * .slots() can contain unicode strings on Python 2. + 2014-11-22 -- 1.3.2 diff --git a/astroid/scoped_nodes.py b/astroid/scoped_nodes.py index 898361dd..372cd9c2 100644 --- a/astroid/scoped_nodes.py +++ b/astroid/scoped_nodes.py @@ -1366,7 +1366,8 @@ class Class(Statement, LocalsDictNodeNG, FilterStmtsMixin): if infered is YES: continue if (not isinstance(infered, Const) or - not isinstance(infered.value, str)): + not isinstance(infered.value, + six.string_types)): continue if not infered.value: continue diff --git a/astroid/tests/unittest_scoped_nodes.py b/astroid/tests/unittest_scoped_nodes.py index c01adae2..9b622130 100644 --- a/astroid/tests/unittest_scoped_nodes.py +++ b/astroid/tests/unittest_scoped_nodes.py @@ -1084,6 +1084,18 @@ class ClassNodeTest(ModuleLoader, unittest.TestCase): [slot.value for slot in tenth_slots], ["a", "c"]) + @test_utils.require_version(maxver='3.0') + def test_slots_py2(self): + module = test_utils.build_module(""" + class UnicodeSlots(object): + __slots__ = (u"a", u"b", "c") + """) + slots = module['UnicodeSlots'].slots() + self.assertEqual(len(slots), 3) + self.assertEqual(slots[0].value, "a") + self.assertEqual(slots[1].value, "b") + self.assertEqual(slots[2].value, "c") + def assertEqualMro(self, klass, expected_mro): self.assertEqual( [member.name for member in klass.mro()], -- cgit v1.2.1