MCPcopy Index your code
hub / github.com/python/cpython / test_annotated

Method test_annotated

Lib/test/test_symtable.py:331–356  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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())

Callers

nothing calls this directly

Calls 9

get_typeMethod · 0.80
assertTrueMethod · 0.80
is_localMethod · 0.80
is_annotatedMethod · 0.80
assertFalseMethod · 0.80
get_childrenMethod · 0.45
assertEqualMethod · 0.45
lookupMethod · 0.45
is_globalMethod · 0.45

Tested by

no test coverage detected