diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/symtable.py | 9 | ||||
-rw-r--r-- | Lib/test/doctest_aliases.py | 2 | ||||
-rw-r--r-- | Lib/test/test_ast.py | 10 | ||||
-rw-r--r-- | Lib/test/test_compile.py | 4 | ||||
-rw-r--r-- | Lib/test/test_doctest.py | 2 | ||||
-rw-r--r-- | Lib/test/test_generators.py | 8 | ||||
-rw-r--r-- | Lib/test/test_symtable.py | 2 | ||||
-rw-r--r-- | Lib/test/test_syntax.py | 6 | ||||
-rw-r--r-- | Lib/test/test_with.py | 10 |
9 files changed, 34 insertions, 19 deletions
diff --git a/Lib/symtable.py b/Lib/symtable.py index 7548a7f..7277f5e 100644 --- a/Lib/symtable.py +++ b/Lib/symtable.py @@ -2,9 +2,8 @@ import _symtable from _symtable import (USE, DEF_GLOBAL, DEF_LOCAL, DEF_PARAM, - DEF_FREE_GLOBAL, DEF_FREE_CLASS, DEF_IMPORT, DEF_BOUND, - OPT_IMPORT_STAR, SCOPE_OFF, SCOPE_MASK, FREE, - GLOBAL_IMPLICIT, GLOBAL_EXPLICIT) + DEF_IMPORT, DEF_BOUND, OPT_IMPORT_STAR, SCOPE_OFF, SCOPE_MASK, FREE, + LOCAL, GLOBAL_IMPLICIT, GLOBAL_EXPLICIT) import weakref @@ -138,7 +137,9 @@ class Function(SymbolTable): def get_locals(self): if self.__locals is None: - self.__locals = self.__idents_matching(lambda x:x & DEF_BOUND) + test = lambda x: (((x >> SCOPE_OFF) & SCOPE_MASK) == LOCAL or + (x & DEF_BOUND and not x & DEF_GLOBAL)) + self.__locals = self.__idents_matching(test) return self.__locals def get_globals(self): diff --git a/Lib/test/doctest_aliases.py b/Lib/test/doctest_aliases.py index e5e6b29..30cefaf 100644 --- a/Lib/test/doctest_aliases.py +++ b/Lib/test/doctest_aliases.py @@ -10,4 +10,4 @@ class TwoNames: ''' return 'f' - g = f # define an alias for f + g = f # define an alias for f diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py index 54a3b35..021ae95 100644 --- a/Lib/test/test_ast.py +++ b/Lib/test/test_ast.py @@ -140,6 +140,16 @@ class AST_Tests(unittest.TestCase): self.assertEquals(to_tuple(ast_tree), o) self._assert_order(ast_tree, (0, 0)) + def test_slice(self): + slc = ast.parse("x[::]").body[0].value.slice + self.assertIsNone(slc.upper) + self.assertIsNone(slc.lower) + self.assertIsNone(slc.step) + + def test_from_import(self): + im = ast.parse("from . import y").body[0] + self.assertIsNone(im.module) + def test_nodeclasses(self): x = ast.BinOp(1, 2, 3, lineno=0) self.assertEquals(x.left, 1) diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py index 2b978eb..ae8a648 100644 --- a/Lib/test/test_compile.py +++ b/Lib/test/test_compile.py @@ -213,6 +213,10 @@ if 1: '(a, None) = 0, 0', 'for None in range(10): pass', 'def f(None): pass', + 'import None', + 'import x as None', + 'from x import None', + 'from x import y as None' ] for stmt in stmts: stmt += "\n" diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py index 8dcc8a4..59ba74f 100644 --- a/Lib/test/test_doctest.py +++ b/Lib/test/test_doctest.py @@ -498,6 +498,8 @@ If a single object is listed twice (under different names), then tests will only be generated for it once: >>> from test import doctest_aliases + >>> assert doctest_aliases.TwoNames.f + >>> assert doctest_aliases.TwoNames.g >>> tests = excl_empty_finder.find(doctest_aliases) >>> print(len(tests)) 2 diff --git a/Lib/test/test_generators.py b/Lib/test/test_generators.py index 84028e8..90af15b 100644 --- a/Lib/test/test_generators.py +++ b/Lib/test/test_generators.py @@ -960,11 +960,11 @@ Lambdas shouldn't have their usual return behavior. # iterators have side-effects, so that which values *can* be generated at # each slot depend on the values iterated at previous slots. -def conjoin(gs): +def simple_conjoin(gs): values = [None] * len(gs) - def gen(i, values=values): + def gen(i): if i >= len(gs): yield values else: @@ -989,7 +989,7 @@ def conjoin(gs): # Do one loop nest at time recursively, until the # of loop nests # remaining is divisible by 3. - def gen(i, values=values): + def gen(i): if i >= n: yield values @@ -1007,7 +1007,7 @@ def conjoin(gs): # remain. Don't call directly: this is an internal optimization for # gen's use. - def _gen3(i, values=values): + def _gen3(i): assert i < n and (n-i) % 3 == 0 ip1, ip2, ip3 = i+1, i+2, i+3 g, g1, g2 = gs[i : ip3] diff --git a/Lib/test/test_symtable.py b/Lib/test/test_symtable.py index 45b7be8..f567c63 100644 --- a/Lib/test/test_symtable.py +++ b/Lib/test/test_symtable.py @@ -82,7 +82,7 @@ class SymtableTest(unittest.TestCase): func = self.spam self.assertEqual(func.get_parameters(), ("a", "b", "kw", "var")) self.assertEqual(func.get_locals(), - ("a", "b", "bar", "glob", "internal", "kw", "var", "x")) + ("a", "b", "internal", "kw", "var", "x")) self.assertEqual(func.get_globals(), ("bar", "glob")) self.assertEqual(self.internal.get_frees(), ("x",)) diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py index c55171a..f422d2d 100644 --- a/Lib/test/test_syntax.py +++ b/Lib/test/test_syntax.py @@ -476,6 +476,12 @@ Traceback (most recent call last): ... SyntaxError: keyword argument repeated +>>> del () +Traceback (most recent call last): + ... + File "<doctest test.test_syntax[50]>", line 1 +SyntaxError: can't delete () + """ import re diff --git a/Lib/test/test_with.py b/Lib/test/test_with.py index ae2fa4d..f59032e 100644 --- a/Lib/test/test_with.py +++ b/Lib/test/test_with.py @@ -285,15 +285,6 @@ class NestedNonexceptionalTestCase(unittest.TestCase, with Nested(mock_contextmanager_generator()): pass - def testSingleArgUnbound(self): - mock_contextmanager = mock_contextmanager_generator() - mock_nested = MockNested(mock_contextmanager) - with mock_nested: - self.assertInWithManagerInvariants(mock_contextmanager) - self.assertInWithManagerInvariants(mock_nested) - self.assertAfterWithManagerInvariantsNoError(mock_contextmanager) - self.assertAfterWithManagerInvariantsNoError(mock_nested) - def testSingleArgBoundToNonTuple(self): m = mock_contextmanager_generator() # This will bind all the arguments to nested() into a single list @@ -721,6 +712,7 @@ class NestedWith(unittest.TestCase): body_executed = True self.assertTrue(a.enter_called) self.assertTrue(a.exit_called) + self.assertTrue(body_executed) self.assertNotEqual(a.exc_info[0], None) def testEnterReturnsTuple(self): |