Browse Source
bpo-35113: Fix inspect.getsource to return correct source for inner classes (#10307)
bpo-35113: Fix inspect.getsource to return correct source for inner classes (#10307)
* Use ast module to find class definition * Add NEWS entry * Fix class with multiple children and move decorator code to the method * Fix PR comments 1. Use node.decorator_list to select decorators 2. Remove unwanted variables in ClassVisitor 3. Simplify stack management as per review * Add test for nested functions and async calls * Fix pydoc test since comments are returned now correctly * Set event loop policy as None to fix environment related change * Refactor visit_AsyncFunctionDef and tests * Refactor to use local variables and fix tests * Add patch attribution * Use self.addCleanup for asyncio * Rename ClassVisitor to ClassFinder and fix asyncio cleanup * Return first class inside conditional in case of multiple definitions. Remove decorator for class source. * Add docstring to make the test correct * Modify NEWS entry regarding decorators * Return decorators too for bpo-15856 * Move ast and the class source code to top. Use proper Exception.pull/19587/head
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 200 additions and 23 deletions
-
65Lib/inspect.py
-
114Lib/test/inspect_fodder2.py
-
40Lib/test/test_inspect.py
-
1Lib/test/test_pydoc.py
-
3Misc/NEWS.d/next/Library/2018-11-03-16-18-20.bpo-35113.vwvWKG.rst
@ -0,0 +1,3 @@ |
|||
:meth:`inspect.getsource` now returns correct source code for inner class |
|||
with same name as module level class. Decorators are also returned as part |
|||
of source of the class. Patch by Karthikeyan Singaravelan. |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue