|
2 | 2 | Test the API of the symtable module. |
3 | 3 | """ |
4 | 4 |
|
5 | | -import re |
6 | | -import textwrap |
7 | 5 | import symtable |
8 | 6 | import warnings |
9 | 7 | import unittest |
@@ -364,87 +362,6 @@ def test_name(self): |
364 | 362 | self.assertEqual(self.spam.lookup("x").get_name(), "x") |
365 | 363 | self.assertEqual(self.Mine.get_name(), "Mine") |
366 | 364 |
|
367 | | - def test_class_get_methods(self): |
368 | | - deprecation_mess = ( |
369 | | - re.escape('symtable.Class.get_methods() is deprecated ' |
370 | | - 'and will be removed in Python 3.16.') |
371 | | - ) |
372 | | - |
373 | | - with self.assertWarnsRegex(DeprecationWarning, deprecation_mess): |
374 | | - self.assertEqual(self.Mine.get_methods(), ('a_method',)) |
375 | | - |
376 | | - top = symtable.symtable(TEST_COMPLEX_CLASS_CODE, "?", "exec") |
377 | | - this = find_block(top, "ComplexClass") |
378 | | - |
379 | | - with self.assertWarnsRegex(DeprecationWarning, deprecation_mess): |
380 | | - self.assertEqual(this.get_methods(), ( |
381 | | - 'a_method', 'a_method_pep_695', |
382 | | - 'an_async_method', 'an_async_method_pep_695', |
383 | | - 'a_classmethod', 'a_classmethod_pep_695', |
384 | | - 'an_async_classmethod', 'an_async_classmethod_pep_695', |
385 | | - 'a_staticmethod', 'a_staticmethod_pep_695', |
386 | | - 'an_async_staticmethod', 'an_async_staticmethod_pep_695', |
387 | | - 'a_fakemethod', 'a_fakemethod_pep_695', |
388 | | - 'an_async_fakemethod', 'an_async_fakemethod_pep_695', |
389 | | - 'glob_unassigned_meth', 'glob_unassigned_meth_pep_695', |
390 | | - 'glob_unassigned_async_meth', 'glob_unassigned_async_meth_pep_695', |
391 | | - 'glob_assigned_meth', 'glob_assigned_meth_pep_695', |
392 | | - 'glob_assigned_async_meth', 'glob_assigned_async_meth_pep_695', |
393 | | - )) |
394 | | - |
395 | | - # Test generator expressions that are of type TYPE_FUNCTION |
396 | | - # but will not be reported by get_methods() since they are |
397 | | - # not functions per se. |
398 | | - # |
399 | | - # Other kind of comprehensions such as list, set or dict |
400 | | - # expressions do not have the TYPE_FUNCTION type. |
401 | | - |
402 | | - def check_body(body, expected_methods): |
403 | | - indented = textwrap.indent(body, ' ' * 4) |
404 | | - top = symtable.symtable(f"class A:\n{indented}", "?", "exec") |
405 | | - this = find_block(top, "A") |
406 | | - with self.assertWarnsRegex(DeprecationWarning, deprecation_mess): |
407 | | - self.assertEqual(this.get_methods(), expected_methods) |
408 | | - |
409 | | - # statements with 'genexpr' inside it |
410 | | - GENEXPRS = ( |
411 | | - 'x = (x for x in [])', |
412 | | - 'x = (x async for x in [])', |
413 | | - 'type x[genexpr = (x for x in [])] = (x for x in [])', |
414 | | - 'type x[genexpr = (x async for x in [])] = (x async for x in [])', |
415 | | - 'genexpr = (x for x in [])', |
416 | | - 'genexpr = (x async for x in [])', |
417 | | - 'type genexpr[genexpr = (x for x in [])] = (x for x in [])', |
418 | | - 'type genexpr[genexpr = (x async for x in [])] = (x async for x in [])', |
419 | | - ) |
420 | | - |
421 | | - for gen in GENEXPRS: |
422 | | - # test generator expression |
423 | | - with self.subTest(gen=gen): |
424 | | - check_body(gen, ()) |
425 | | - |
426 | | - # test generator expression + variable named 'genexpr' |
427 | | - with self.subTest(gen=gen, isvar=True): |
428 | | - check_body('\n'.join((gen, 'genexpr = 1')), ()) |
429 | | - check_body('\n'.join(('genexpr = 1', gen)), ()) |
430 | | - |
431 | | - for paramlist in ('()', '(x)', '(x, y)', '(z: T)'): |
432 | | - for func in ( |
433 | | - f'def genexpr{paramlist}:pass', |
434 | | - f'async def genexpr{paramlist}:pass', |
435 | | - f'def genexpr[T]{paramlist}:pass', |
436 | | - f'async def genexpr[T]{paramlist}:pass', |
437 | | - ): |
438 | | - with self.subTest(func=func): |
439 | | - # test function named 'genexpr' |
440 | | - check_body(func, ('genexpr',)) |
441 | | - |
442 | | - for gen in GENEXPRS: |
443 | | - with self.subTest(gen=gen, func=func): |
444 | | - # test generator expression + function named 'genexpr' |
445 | | - check_body('\n'.join((gen, func)), ('genexpr',)) |
446 | | - check_body('\n'.join((func, gen)), ('genexpr',)) |
447 | | - |
448 | 365 | def test_filename_correct(self): |
449 | 366 | ### Bug tickler: SyntaxError file name correct whether error raised |
450 | 367 | ### while parsing or building symbol table. |
|
0 commit comments