Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
gh-119698: fix symtable.Class.get_methods and document its behaviour correctly#120151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
5b23892
fix `symtable.Class.get_methods`
picnixz 93ea543
add test
picnixz 44f50e2
add doc
picnixz f8b95d3
blurb
picnixz 582906b
fixup
picnixz f64e302
fixup whitespaces
picnixz 6078d24
fixup
picnixz f795499
fixup
picnixz 8d1f661
improve test coverage
picnixz 3cbde0d
Merge branch 'main' into fix-symtable-get-methods
picnixz fc7f5bb
add async def cases
picnixz 1352d08
update comments
picnixz 62d2d6d
prepare for handling PEP 649
picnixz bd05537
unapply restyle
picnixz 7dbf06c
improve test
picnixz 5510444
normalize declaration order
picnixz b13676f
improve example
picnixz b438019
Merge branch 'main' into fix-symtable-get-methods
picnixz 3d3692d
Merge branch 'main' into fix-symtable-get-methods
picnixz 5227b50
Merge branch 'main' into fix-symtable-get-methods
picnixz 26e6038
Update Doc/library/symtable.rst
picnixz 33d9391
Merge branch 'main' into fix-symtable-get-methods
picnixz a8264e1
Merge branch 'main' into fix-symtable-get-methods
picnixz f33f998
fix typo...
picnixz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -13,7 +13,7 @@ | ||
| glob = 42 | ||
| some_var = 12 | ||
| some_non_assigned_global_var = 11 | ||
| some_non_assigned_global_var: int | ||
| some_assigned_global_var = 11 | ||
| class Mine: | ||
| @@ -53,6 +53,120 @@ class GenericMine[T: int]: | ||
| pass | ||
| """ | ||
| TEST_COMPLEX_CLASS_CODE = """ | ||
| # The following symbols are defined in ComplexClass | ||
| # without being introduced by a 'global' statement. | ||
| glob_unassigned_meth: Any | ||
| glob_unassigned_meth_pep_695: Any | ||
| glob_unassigned_async_meth: Any | ||
| glob_unassigned_async_meth_pep_695: Any | ||
| def glob_assigned_meth(): pass | ||
| def glob_assigned_meth_pep_695[T](): pass | ||
| async def glob_assigned_async_meth(): pass | ||
| async def glob_assigned_async_meth_pep_695[T](): pass | ||
| # The following symbols are defined in ComplexClass after | ||
| # being introduced by a 'global' statement (and therefore | ||
| # are not considered as local symbols of ComplexClass). | ||
| glob_unassigned_meth_ignore: Any | ||
| glob_unassigned_meth_pep_695_ignore: Any | ||
| glob_unassigned_async_meth_ignore: Any | ||
| glob_unassigned_async_meth_pep_695_ignore: Any | ||
| def glob_assigned_meth_ignore(): pass | ||
| def glob_assigned_meth_pep_695_ignore[T](): pass | ||
| async def glob_assigned_async_meth_ignore(): pass | ||
| async def glob_assigned_async_meth_pep_695_ignore[T](): pass | ||
| class ComplexClass: | ||
| a_var = 1234 | ||
| a_genexpr = (x for x in []) | ||
| a_lambda = lambda x: x | ||
| type a_type_alias = int | ||
| type a_type_alias_pep_695[T] = list[T] | ||
| class a_class: pass | ||
| class a_class_pep_695[T]: pass | ||
| def a_method(self): pass | ||
| def a_method_pep_695[T](self): pass | ||
| async def an_async_method(self): pass | ||
| async def an_async_method_pep_695[T](self): pass | ||
| @classmethod | ||
| def a_classmethod(cls): pass | ||
| @classmethod | ||
| def a_classmethod_pep_695[T](self): pass | ||
| @classmethod | ||
| async def an_async_classmethod(cls): pass | ||
| @classmethod | ||
| async def an_async_classmethod_pep_695[T](self): pass | ||
| @staticmethod | ||
| def a_staticmethod(): pass | ||
| @staticmethod | ||
| def a_staticmethod_pep_695[T](self): pass | ||
| @staticmethod | ||
| async def an_async_staticmethod(): pass | ||
| @staticmethod | ||
| async def an_async_staticmethod_pep_695[T](self): pass | ||
| # These ones will be considered as methods because of the 'def' although | ||
| # they are *not* valid methods at runtime since they are not decorated | ||
| # with @staticmethod. | ||
| def a_fakemethod(): pass | ||
| def a_fakemethod_pep_695[T](): pass | ||
| async def an_async_fakemethod(): pass | ||
| async def an_async_fakemethod_pep_695[T](): pass | ||
| # Check that those are still considered as methods | ||
| # since they are not using the 'global' keyword. | ||
| def glob_unassigned_meth(): pass | ||
| def glob_unassigned_meth_pep_695[T](): pass | ||
| async def glob_unassigned_async_meth(): pass | ||
| async def glob_unassigned_async_meth_pep_695[T](): pass | ||
| def glob_assigned_meth(): pass | ||
| def glob_assigned_meth_pep_695[T](): pass | ||
| async def glob_assigned_async_meth(): pass | ||
| async def glob_assigned_async_meth_pep_695[T](): pass | ||
| # The following are not picked as local symbols because they are not | ||
| # visible by the class at runtime (this is equivalent to having the | ||
| # definitions outside of the class). | ||
| global glob_unassigned_meth_ignore | ||
| def glob_unassigned_meth_ignore(): pass | ||
| global glob_unassigned_meth_pep_695_ignore | ||
| def glob_unassigned_meth_pep_695_ignore[T](): pass | ||
| global glob_unassigned_async_meth_ignore | ||
| async def glob_unassigned_async_meth_ignore(): pass | ||
| global glob_unassigned_async_meth_pep_695_ignore | ||
| async def glob_unassigned_async_meth_pep_695_ignore[T](): pass | ||
| global glob_assigned_meth_ignore | ||
| def glob_assigned_meth_ignore(): pass | ||
| global glob_assigned_meth_pep_695_ignore | ||
| def glob_assigned_meth_pep_695_ignore[T](): pass | ||
picnixz marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| global glob_assigned_async_meth_ignore | ||
| async def glob_assigned_async_meth_ignore(): pass | ||
| global glob_assigned_async_meth_pep_695_ignore | ||
| async def glob_assigned_async_meth_pep_695_ignore[T](): pass | ||
| """ | ||
| def find_block(block, name): | ||
| for ch in block.get_children(): | ||
| @@ -65,6 +179,7 @@ class SymtableTest(unittest.TestCase): | ||
| top = symtable.symtable(TEST_CODE, "?", "exec") | ||
| # These correspond to scopes in TEST_CODE | ||
| Mine = find_block(top, "Mine") | ||
| a_method = find_block(Mine, "a_method") | ||
| spam = find_block(top, "spam") | ||
| internal = find_block(spam, "internal") | ||
| @@ -242,6 +357,24 @@ def test_name(self): | ||
| def test_class_info(self): | ||
| self.assertEqual(self.Mine.get_methods(), ('a_method',)) | ||
| top = symtable.symtable(TEST_COMPLEX_CLASS_CODE, "?", "exec") | ||
| this = find_block(top, "ComplexClass") | ||
| self.assertEqual(this.get_methods(), ( | ||
| 'a_method', 'a_method_pep_695', | ||
| 'an_async_method', 'an_async_method_pep_695', | ||
| 'a_classmethod', 'a_classmethod_pep_695', | ||
| 'an_async_classmethod', 'an_async_classmethod_pep_695', | ||
| 'a_staticmethod', 'a_staticmethod_pep_695', | ||
| 'an_async_staticmethod', 'an_async_staticmethod_pep_695', | ||
| 'a_fakemethod', 'a_fakemethod_pep_695', | ||
| 'an_async_fakemethod', 'an_async_fakemethod_pep_695', | ||
| 'glob_unassigned_meth', 'glob_unassigned_meth_pep_695', | ||
| 'glob_unassigned_async_meth', 'glob_unassigned_async_meth_pep_695', | ||
| 'glob_assigned_meth', 'glob_assigned_meth_pep_695', | ||
| 'glob_assigned_async_meth', 'glob_assigned_async_meth_pep_695', | ||
| )) | ||
| def test_filename_correct(self): | ||
| ### Bug tickler: SyntaxError file name correct whether error raised | ||
| ### while parsing or building symbol table. | ||
2 changes: 2 additions & 0 deletions
2 Misc/NEWS.d/next/Library/2024-06-06-12-07-57.gh-issue-119698.rRrprk.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Fix :meth:`symtable.Class.get_methods` and document its behaviour. Patch by | ||
| Bénédikt Tran. |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.