summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_inspect.py
Commit message (Collapse)AuthorAgeFilesLines
* [3.11] gh-108303: Move all inspect test files to `test_inspect/` (GH-109607) ↵Nikita Sobolev2023-10-311-4515/+0
| | | | (#111543)
* [3.11] gh-109625: Move _ready_to_import() from test_import to ↵Nikita Sobolev2023-09-221-4/+2
| | | | | | support.import_helper (GH-109626) (#109718) [3.11] gh-109625: Move _ready_to_import() from test_import to support.import_helper (GH-109626). (cherry picked from commit 115c49ad5a5ccfb628fef3ae06a566f7a0197f97)
* [3.11] gh-108303: Move `ann_module*.py` files to `typinganndata/` folder ↵Victor Stinner2023-09-211-1/+1
| | | | | | | | | (#108354) (#109673) gh-108303: Move `ann_module*.py` files to `typinganndata/` folder (#108354) (cherry picked from commit 3f61cf646d0506baa0c0c2118f05110446519c62) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
* [3.11] gh-105080: Fixed inconsistent signature on derived classes (GH… ↵Tian Gao2023-06-041-0/+18
| | | | (#105274)
* [3.11] gh-75367: Fix data descriptor detection in inspect.getattr_static ↵Miss Islington (bot)2023-05-161-0/+3
| | | | | | | | | (GH-104517) (#104557) gh-75367: Fix data descriptor detection in inspect.getattr_static (GH-104517) (cherry picked from commit 5e9f471e7db30893fb3f42681f17fdcdb70069ee) Co-authored-by: Furkan Onder <furkanonder@protonmail.com> Co-authored-by: Carl Meyer <carl@oddbird.net>
* [3.11] gh-103193: Improve `getattr_static` test coverage (GH-104286) (#104290)Miss Islington (bot)2023-05-081-0/+29
| | | | | | gh-103193: Improve `getattr_static` test coverage (GH-104286) (cherry picked from commit 921185ed050efbca2f0adeab79f676b7f8cc3660) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* [3.11] gh-103556: [inspect.Signature] disallow pos-or-kw params without ↵Miss Islington (bot)2023-04-221-6/+34
| | | | default after pos-only with default (GH-103557) (#103675)
* gh-103553: Improve `test_inspect`: add more assertions, remove unused ↵Miss Islington (bot)2023-04-151-15/+9
| | | | | | | (GH-103554) (cherry picked from commit 4fe1c4b97e39429abbb9c2117fe40f585de00887) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
* gh-103406: Modernize pos-only arguments usage in `test_signature` (GH-103407)Miss Islington (bot)2023-04-141-20/+11
| | | | | (cherry picked from commit 756978117698eeac3af270db25d22599e681bcb3) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
* [3.11] gh-96127: Fix `inspect.signature` call on mocks (#96335) (#101646)Oleg Iarygin2023-02-081-0/+19
| | | | | (cherry picked from commit 9e7d7266ecdcccc02385fe4ccb094f3444102e26) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
* [3.11] gh-85267: Improvements to inspect.signature __text_signature__ ↵Shantanu2022-12-211-1/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | handling (GH-98796) (#100392) This makes a couple related changes to inspect.signature's behaviour when parsing a signature from `__text_signature__`. First, `inspect.signature` is documented as only raising ValueError or TypeError. However, in some cases, we could raise RuntimeError. This PR changes that, thereby fixing GH-83685. (Note that the new ValueErrors in RewriteSymbolics are caught and then reraised with a message) Second, `inspect.signature` could randomly drop parameters that it didn't understand (corresponding to `return None` in the `p` function). This is the core issue in GH-85267. I think this is very surprising behaviour and it seems better to fail outright. Third, adding this new failure broke a couple tests. To fix them (and to e.g. allow `inspect.signature(select.epoll.register)` as in GH-85267), I add constant folding of a couple binary operations to RewriteSymbolics. (There's some discussion of making signature expression evaluation arbitrary powerful in GH-68155. I think that's out of scope. The additional constant folding here is pretty straightforward, useful, and not much of a slippery slope) Fourth, while GH-85267 is incorrect about the cause of the issue, it turns out if you had consecutive newlines in __text_signature__, you'd get `tokenize.TokenError`. Finally, the `if name is invalid:` code path was dead, since `parse_name` never returned `invalid`.. (cherry picked from commit 79311cbfe718f17c89bab67d7f89da3931bfa2ac) Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
* gh-83035: handle decorator with nested parens in inspect.getsource (GH-99654)Miss Islington (bot)2022-12-071-0/+6
| | | | | (cherry picked from commit 68e41295b8611a990de68f15c89f1eb3dea51867) Co-authored-by: Carl Meyer <carl@oddbird.net>
* gh-74044: inspect.signature for wrappers around decorated bound methods (GH-736)Miss Islington (bot)2022-11-101-2/+7
| | | | | (cherry picked from commit dbf2faf579b4094387d65ee41f049456ca67c446) Co-authored-by: Anton Ryzhov <anton@ryzhov.me>
* GH-96073: Fix wild replacement in inspect.formatannotation (GH-96074)Miss Islington (bot)2022-10-071-0/+7
| | | | | | Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> (cherry picked from commit d5fea01d9d439b1638cd8e5db19c33909841d86f) Co-authored-by: Anh71me <iyumelive@gmail.com>
* gh-84753: Make inspect.iscoroutinefunction() work with AsyncMock (GH-94050) ↵Miss Islington (bot)2022-06-301-0/+14
| | | | | | | | | | | | | | (GH-94460) The inspect version was not working with unittest.mock.AsyncMock. The fix introduces special-casing of AsyncMock in `inspect.iscoroutinefunction` equivalent to the one performed in `asyncio.iscoroutinefunction`. Co-authored-by: Łukasz Langa <lukasz@langa.pl> (cherry picked from commit 4261b6bffc0b8bb5c6d4d80578a81b7520f4aefc) Co-authored-by: Mehdi ABAAKOUK <sileht@sileht.net>
* [3.11] gh-90473: Skip tests that don't apply to Emscripten and WASI ↵Christian Heimes2022-05-161-1/+4
| | | | | (GH-92846) (GH-92851) Co-authored-by: Christian Heimes <christian@python.org>
* gh-92062: `inspect.Parameter` checks whether `name` is a keyword (GH-92065)Zac Hatfield-Dodds2022-05-031-0/+3
| | | Fixes #92062.
* gh-88116: Enhance the inspect frame APIs to use the extended position ↵Pablo Galindo Salgado2022-04-231-7/+21
| | | | information (GH-91531)
* bpo-29418: Implement inspect.ismethodwrapper and fix inspect.isroutine for ↵Hakan Çelik2022-02-161-3/+43
| | | | | cases where methodwrapper is given (GH-19261) Automerge-Triggered-By: GH:isidentical
* bpo-40280: Address more test failures on Emscripten (GH-31050)Christian Heimes2022-02-051-0/+1
| | | Co-authored-by: Brett Cannon <brett@python.org>
* bpo-46565: `del` loop vars that are leaking into module namespaces (GH-30993)Nikita Sobolev2022-02-031-1/+1
|
* bpo-46103: Fix inspect.getmembers to only get __bases__ from class (GH-30147)Weipeng Hong2022-01-231-0/+5
|
* bpo-43118: Fix bug in inspect.signature around 'base.__text_signature__' ↵Weipeng Hong2022-01-211-0/+11
| | | | (GH-30285)
* bpo-46411: Remove unnecessary calls to sys.exc_info() in tests (GH-30638)Irit Katriel2022-01-181-2/+2
|
* Remove spaces in empty lines (GH-30121)AN Long2021-12-151-1/+1
|
* bpo-27062: add `__all__` to inspect module (GH-30003)Kumar Aditya2021-12-101-0/+3
|
* bpo-30533:Add function inspect.getmembers_static that does not call ↵Weipeng Hong2021-11-301-0/+17
| | | | | | | | | | | | | | | | | | | | | properties or dynamic properties. (#20911) * Add function inspect.getmembers_static that does not call properties or dynamic properties. * update _getmembers args * Update Misc/NEWS.d/next/Library/2020-06-16-18-00-56.bpo-30533.StL57t.rst Co-authored-by: Itamar Ostricher <itamarost@gmail.com> * Update Lib/inspect.py Co-authored-by: Itamar Ostricher <itamarost@gmail.com> * Removes the copy pasted doc string Co-authored-by: Itamar Ostricher <itamarost@gmail.com> Co-authored-by: Dino Viehland <dinoviehland@gmail.com>
* bpo-45406: make inspect.getmodule() return None when getabsfile() raises ↵Irit Katriel2021-11-021-0/+9
| | | | FileNotFoundError (GH-28824)
* bpo-45438: format of inspect.Signature with generic builtins (#29212)Martin Rueckl2021-10-271-0/+11
| | | | | | | Use types.GenericAlias in inspect.formatannotation to correctly add type arguments of builtin types to the string representation of Signatures. Co-authored-by: Martin Rückl <martin.rueckl@codecentric.de>
* bpo-45320: Remove long-deprecated inspect methods (GH-28618)Hugo van Kemenade2021-10-201-94/+14
|
* bpo-45229: Remove test_main in many tests (GH-28405)Serhiy Storchaka2021-09-191-16/+2
| | | | | | | | | Instead of explicitly enumerate test classes for run_unittest() use the unittest ability to discover tests. This also makes these tests discoverable and runnable with unittest. load_tests() can be used for dynamic generating tests and adding doctests. setUpModule(), tearDownModule() and addModuleCleanup() can be used for running code before and after all module tests.
* bpo-44808: fixes test for interactive inspect getsource of a class (GH-27571)andrei kulakov2021-08-031-12/+8
| | | Co-authored-by: Łukasz Langa <lukasz@langa.pl>
* bpo-44808: Fix test_inspect in refleak mode (GH-27544)Pablo Galindo Salgado2021-08-021-1/+2
|
* bpo-44648: Fix error type in inspect.getsource() in interactive session ↵andrei kulakov2021-07-301-1/+16
| | | | (GH-27171)
* bpo-40897:Give priority to using the current class constructor in ↵Weipeng Hong2021-07-161-0/+41
| | | | | `inspect.signature` (#27177) Co-authored-by: Łukasz Langa <lukasz@langa.pl>
* bpo-20684: Remove unused inspect._signature_get_bound_param (GH-21100)Anthony Sottile2021-05-221-7/+0
|
* bpo-43817: Add inspect.get_annotations(). (#25522)larryhastings2021-04-301-5/+238
| | | | | Add inspect.get_annotations, which safely computes the annotations defined on an object. It works around the quirks of accessing the annotations from various types of objects, and makes very few assumptions about the object passed in. inspect.get_annotations can also correctly un-stringize stringized annotations. inspect.signature, inspect.from_callable, and inspect.from_function now call inspect.get_annotations to retrieve annotations. This means inspect.signature and inspect.from_callable can now un-stringize stringized annotations, too.
* bpo-38605: Revert making 'from __future__ import annotations' the default ↵Pablo Galindo2021-04-211-24/+28
| | | | | | (GH-25490) This reverts commits 044a1048ca93d466965afc027b91a5a9eb9ce23c and 1be456ae9d53bb1cba2b24fc86175c282d1c2169, adapting the code to changes that happened after it.
* bpo-43651: PEP 597: Fix EncodingWarning in some tests (GH-25189)Inada Naoki2021-04-061-6/+6
| | | | | | | | | | | | * Fix _sitebuiltins * Fix test_inspect * Fix test_interpreters * Fix test_io * Fix test_iter * Fix test_json * Fix test_linecache * Fix test_lltrace * Fix test_logging * Fix logging
* bpo-31861: Add aiter and anext to builtins (#23847)Joshua Bronson2021-03-231-0/+3
| | | | | | Co-authored-by: jab <jab@users.noreply.github.com> Co-authored-by: Daniel Pope <mauve@mauveweb.co.uk> Co-authored-by: Justin Wang <justin39@gmail.com>
* bpo-41960: Add globalns and localns parameters to inspect.signature and ↵Batuhan Taskaya2020-12-231-0/+20
| | | | Signature.from_callable (GH-22583)
* bpo-17735: inspect.findsource now raises OSError when co_lineno is out of ↵Irit Katriel2020-12-041-0/+11
| | | | | range (GH-23633) This can happen when a file was edited after it was imported.
* bpo-42116: Fix inspect.getsource handling of trailing comments (GH-23630)Irit Katriel2020-12-041-4/+19
|
* bpo-38605: Make 'from __future__ import annotations' the default (GH-20434)Batuhan Taskaya2020-10-061-24/+20
| | | | | The hard part was making all the tests pass; there are some subtle issues here, because apparently the future import wasn't tested very thoroughly in previous Python versions. For example, `inspect.signature()` returned type objects normally (except for forward references), but strings with the future import. We changed it to try and return type objects by calling `typing.get_type_hints()`, but fall back on returning strings if that function fails (which it may do if there are future references in the annotations that require passing in a specific namespace to resolve).
* bpo-40275: Use new test.support helper submodules in tests (GH-21727)Hai Shi2020-08-041-1/+3
|
* bpo-40257: Revert changes to inspect.getdoc() (GH-20073)Serhiy Storchaka2020-05-181-12/+3
|
* bpo-35113: Fix inspect.getsource to return correct source for inner classes ↵Karthikeyan Singaravelan2020-04-181-0/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (#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.
* bpo-40257: Output object's own docstring in pydoc (GH-19479)Serhiy Storchaka2020-04-151-3/+12
|
* bpo-39957: Change Signature.parameters to OrderedDict (GH-18988)Jens Reidel2020-03-181-1/+6
|
* bpo-36350: inspect: Replace OrderedDict with dict. (GH-12412)Rémi Lapeyre2020-01-281-0/+5
|