(self)
| 329 | self.assertFalse(self.internal.lookup("x").is_assigned()) |
| 330 | |
| 331 | def test_annotated(self): |
| 332 | st1 = symtable.symtable('def f():\n x: int\n', 'test', 'exec') |
| 333 | st2 = st1.get_children()[1] |
| 334 | self.assertEqual(st2.get_type(), "function") |
| 335 | self.assertTrue(st2.lookup('x').is_local()) |
| 336 | self.assertTrue(st2.lookup('x').is_annotated()) |
| 337 | self.assertFalse(st2.lookup('x').is_global()) |
| 338 | st3 = symtable.symtable('def f():\n x = 1\n', 'test', 'exec') |
| 339 | st4 = st3.get_children()[1] |
| 340 | self.assertEqual(st4.get_type(), "function") |
| 341 | self.assertTrue(st4.lookup('x').is_local()) |
| 342 | self.assertFalse(st4.lookup('x').is_annotated()) |
| 343 | |
| 344 | # Test that annotations in the global scope are valid after the |
| 345 | # variable is declared as nonlocal. |
| 346 | st5 = symtable.symtable('global x\nx: int', 'test', 'exec') |
| 347 | self.assertTrue(st5.lookup("x").is_global()) |
| 348 | |
| 349 | # Test that annotations for nonlocals are valid after the |
| 350 | # variable is declared as nonlocal. |
| 351 | st6 = symtable.symtable('def g():\n' |
| 352 | ' x = 2\n' |
| 353 | ' def f():\n' |
| 354 | ' nonlocal x\n' |
| 355 | ' x: int', |
| 356 | 'test', 'exec') |
| 357 | |
| 358 | def test_imported(self): |
| 359 | self.assertTrue(self.top.lookup("sys").is_imported()) |
nothing calls this directly
no test coverage detected