diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/_abcoll.py | 4 | ||||
-rw-r--r-- | Lib/ast.py | 12 | ||||
-rw-r--r-- | Lib/ctypes/test/__init__.py | 3 | ||||
-rw-r--r-- | Lib/inspect.py | 5 | ||||
-rw-r--r-- | Lib/test/test_ast.py | 6 | ||||
-rw-r--r-- | Lib/test/test_inspect.py | 11 |
6 files changed, 35 insertions, 6 deletions
diff --git a/Lib/_abcoll.py b/Lib/_abcoll.py index 72f1397..ca82c41 100644 --- a/Lib/_abcoll.py +++ b/Lib/_abcoll.py @@ -283,12 +283,12 @@ class MutableSet(Set): @abstractmethod def add(self, value): - """Return True if it was added, False if already there.""" + """Add an element.""" raise NotImplementedError @abstractmethod def discard(self, value): - """Return True if it was deleted, False if not there.""" + """Remove an element. Do not raise an exception if absent.""" raise NotImplementedError def remove(self, value): @@ -64,6 +64,18 @@ def literal_eval(node_or_string): elif isinstance(node, Name): if node.id in _safe_names: return _safe_names[node.id] + elif isinstance(node, BinOp) and \ + isinstance(node.op, (Add, Sub)) and \ + isinstance(node.right, Num) and \ + isinstance(node.right.n, complex) and \ + isinstance(node.left, Num) and \ + isinstance(node.left.n, (int, float)): + left = node.left.n + right = node.right.n + if isinstance(node.op, Add): + return left + right + else: + return left - right raise ValueError('malformed string') return _convert(node_or_string) diff --git a/Lib/ctypes/test/__init__.py b/Lib/ctypes/test/__init__.py index bdcf62b..1e0460a 100644 --- a/Lib/ctypes/test/__init__.py +++ b/Lib/ctypes/test/__init__.py @@ -67,9 +67,6 @@ def get_tests(package, mask, verbosity, exclude=()): if verbosity > 1: print("Skipped %s: %s" % (modname, detail), file=sys.stderr) continue - except Exception as detail: - print("Warning: could not import %s: %s" % (modname, detail), file=sys.stderr) - continue for name in dir(mod): if name.startswith("_"): continue diff --git a/Lib/inspect.py b/Lib/inspect.py index da55ac6..b84aec0 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -249,7 +249,10 @@ def getmembers(object, predicate=None): Optionally, only return members that satisfy a given predicate.""" results = [] for key in dir(object): - value = getattr(object, key) + try: + value = getattr(object, key) + except AttributeError: + continue if not predicate or predicate(value): results.append((key, value)) results.sort() diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py index 2aa3b8f..54a3b35 100644 --- a/Lib/test/test_ast.py +++ b/Lib/test/test_ast.py @@ -265,6 +265,12 @@ class ASTHelpers_Test(unittest.TestCase): self.assertEqual(ast.literal_eval('(True, False, None)'), (True, False, None)) self.assertRaises(ValueError, ast.literal_eval, 'foo()') + def test_literal_eval_issue4907(self): + self.assertEqual(ast.literal_eval('2j'), 2j) + self.assertEqual(ast.literal_eval('10 + 2j'), 10 + 2j) + self.assertEqual(ast.literal_eval('1.5 - 2j'), 1.5 - 2j) + self.assertRaises(ValueError, ast.literal_eval, '2 + (3 + 4j)') + def test_main(): support.run_unittest(AST_Tests, ASTHelpers_Test) diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index bde6d6c..ac9fcd7 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -99,6 +99,17 @@ class TestPredicates(IsTestBase): self.assert_(inspect.isroutine(mod.spam)) self.assert_(inspect.isroutine([].count)) + def test_get_slot_members(self): + class C(object): + __slots__ = ("a", "b") + + x = C() + x.a = 42 + members = dict(inspect.getmembers(x)) + self.assert_('a' in members) + self.assert_('b' not in members) + + class TestInterpreterStack(IsTestBase): def __init__(self, *args, **kwargs): unittest.TestCase.__init__(self, *args, **kwargs) |