summaryrefslogtreecommitdiffstats
path: root/Lib/inspect.py
Commit message (Collapse)AuthorAgeFilesLines
* gh-94912: Adjusted check for non-standard coroutine function marker. (#100935)Carlton Gibson2023-01-111-2/+0
| | | | | | The initial implementation did not correctly identify explicitly marked class instances. Follow up to 532aa4e4e019812d0388920768ede7c04232ebe1
* gh-85267: Improvements to inspect.signature __text_signature__ handling (#98796)Shantanu2022-12-211-5/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 #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 #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 #85267), I add constant folding of a couple binary operations to RewriteSymbolics. (There's some discussion of making signature expression evaluation arbitrary powerful in #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 #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`.
* gh-94912: Added marker for non-standard coroutine function detection (#99247)Carlton Gibson2022-12-181-2/+24
| | | | | This introduces a new decorator `@inspect.markcoroutinefunction`, which, applied to a sync function, makes it appear async to `inspect.iscoroutinefunction()`.
* gh-100039: enhance __signature__ to work with str and callables (GH-100168)Ethan Furman2022-12-161-1/+9
| | | | | Callables should be either class- or static-methods. Enum now uses the classmethod version to greatly improve the help given for enums and flags.
* gh-83035: handle decorator with nested parens in inspect.getsource (#99654)Carl Meyer2022-12-071-9/+1
|
* gh-99677: Deduplicate self-type in `mro` in `inspect._getmembers` (#99678)Nikita Sobolev2022-11-271-1/+1
| | | Closes #99677
* gh-99815: remove unused 'invalid' sentinel value and code that checks for it ↵Anthony Sottile2022-11-271-7/+1
| | | | in inspect.signature parsing (GH-21104)
* Remove unused local variables in inspect.py (#24218)Yonatan Goldschmidt2022-11-271-2/+1
|
* gh-74044: inspect.signature for wrappers around decorated bound methods (GH-736)Anton Ryzhov2022-11-101-1/+4
|
* GH-83901: Improve Signature.bind error message for missing keyword-only ↵Frazer McLean2022-10-071-2/+6
| | | | | | params (#95347) Fixes GH-83901
* GH-96073: Fix wild replacement in inspect.formatannotation (#96074)Anh71me2022-10-071-1/+4
| | | Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* gh-65961: Do not rely solely on `__cached__` (GH-97990)Brett Cannon2022-10-061-18/+3
| | | Make sure `__spec__.cached` (at minimum) can be used.
* bpo-33587: inspect.getsource: reorder stat on file in linecache (GH-6805)Pankaj Pandey2022-08-261-3/+3
| | | | | | | | | | * inspect.getsource: avoid stat on file in linecache The check for os.path.exists() on source file is postponed in inspect.getsourcefile() until needed avoiding an expensive filesystem stat call and PEP 302 module loader check is moved last for performance since it is an uncommon case.
* gh-84753: Make inspect.iscoroutinefunction() work with AsyncMock (#94050)Mehdi ABAAKOUK2022-06-301-1/+1
| | | | | | | | | 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>
* gh-92062: `inspect.Parameter` checks whether `name` is a keyword (GH-92065)Zac Hatfield-Dodds2022-05-031-3/+7
| | | Fixes #92062.
* gh-88116: Enhance the inspect frame APIs to use the extended position ↵Pablo Galindo Salgado2022-04-231-7/+54
| | | | information (GH-91531)
* bpo-29418: Implement inspect.ismethodwrapper and fix inspect.isroutine for ↵Hakan Çelik2022-02-161-9/+11
| | | | | cases where methodwrapper is given (GH-19261) Automerge-Triggered-By: GH:isidentical
* bpo-46565: `del` loop vars that are leaking into module namespaces (GH-30993)Nikita Sobolev2022-02-031-0/+1
|
* bpo-46103: Fix inspect.getmembers to only get __bases__ from class (GH-30147)Weipeng Hong2022-01-231-13/+13
|
* bpo-43118: Fix bug in inspect.signature around 'base.__text_signature__' ↵Weipeng Hong2022-01-211-2/+2
| | | | (GH-30285)
* bpo-46409: Make generators in bytecode (GH-30633)Mark Shannon2022-01-201-6/+6
| | | | | | | | | | | | * Add RETURN_GENERATOR and JUMP_NO_INTERRUPT opcodes. * Trim frame and generator by word each. * Minor refactor of frame.c * Update test.test_sys to account for smaller frames. * Treat generator functions as normal functions when evaluating and specializing.
* bpo-40066: [Enum] skip failing doc test (GH-30637)Kumar Aditya2022-01-171-16/+14
|
* Revert "bpo-40066: [Enum] update str() and format() output (GH-30582)" ↵Victor Stinner2022-01-171-14/+16
| | | | | (GH-30632) This reverts commit acf7403f9baea3ae1119fc6b4a3298522188bf96.
* bpo-40066: [Enum] update str() and format() output (GH-30582)Ethan Furman2022-01-161-16/+14
| | | | | | | | | | | | | | | Undo rejected PEP-663 changes: - restore `repr()` to its 3.10 status - restore `str()` to its 3.10 status New changes: - `IntEnum` and `IntFlag` now leave `__str__` as the original `int.__str__` so that str() and format() return the same result - zero-valued flags without a name have a slightly changed repr(), e.g. `repr(Color(0)) == '<Color: 0>'` - update `dir()` for mixed-in types to return all the methods and attributes of the mixed-in type - added `_numeric_repr_` to `Flag` to control display of unnamed values - enums without doc strings have a more comprehensive doc string added - `ReprEnum` added -- inheriting from this makes it so only `__repr__` is replaced, not `__str__` nor `__format__`; `IntEnum`, `IntFlag`, and `StrEnum` all inherit from `ReprEnum`
* Remove spaces in empty lines (GH-30121)AN Long2021-12-151-3/+3
|
* bpo-27062: add `__all__` to inspect module (GH-30003)Kumar Aditya2021-12-101-1/+100
|
* bpo-30533:Add function inspect.getmembers_static that does not call ↵Weipeng Hong2021-11-301-4/+21
| | | | | | | | | | | | | | | | | | | | | 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-1/+1
| | | | FileNotFoundError (GH-28824)
* bpo-45438: format of inspect.Signature with generic builtins (#29212)Martin Rueckl2021-10-271-0/+2
| | | | | | | 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-113/+0
|
* bpo-30951: Correct co_names docstring in inspect module (GH-2743)Alex Vig2021-09-241-1/+1
|
* bpo-44648: Fix error type in inspect.getsource() in interactive session ↵andrei kulakov2021-07-301-0/+2
| | | | (GH-27171)
* bpo-40897:Give priority to using the current class constructor in ↵Weipeng Hong2021-07-161-8/+16
| | | | | `inspect.signature` (#27177) Co-authored-by: Łukasz Langa <lukasz@langa.pl>
* bpo-35113: clean up duplicate import and comment (#27073)andrei kulakov2021-07-131-4/+0
|
* bpo-20684: Remove unused inspect._signature_get_bound_param (GH-21100)Anthony Sottile2021-05-221-23/+0
|
* bpo-43817: Add inspect.get_annotations(). (#25522)larryhastings2021-04-301-14/+135
| | | | | 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-17/+2
| | | | | | (GH-25490) This reverts commits 044a1048ca93d466965afc027b91a5a9eb9ce23c and 1be456ae9d53bb1cba2b24fc86175c282d1c2169, adapting the code to changes that happened after it.
* bpo-40066: Enum: modify `repr()` and `str()` (GH-22392)Ethan Furman2021-03-311-3/+0
| | | | | | | | | * Enum: streamline repr() and str(); improve docs - repr() is now ``enum_class.member_name`` - stdlib global enums are ``module_name.member_name`` - str() is now ``member_name`` - add HOW-TO section for ``Enum`` - change main documentation to be an API reference
* bpo-42901: [Enum] move member creation to `__set_name__` (GH-24196)Ethan Furman2021-01-131-1/+1
| | | | | | | | | | | `type.__new__` calls `__set_name__` and `__init_subclass__`, which means that any work metaclasses do after calling `super().__new__()` will not be available to those two methods. In particular, `Enum` classes that want to make use of `__init_subclass__` will not see any members. Almost all customization is therefore moved to before the `type.__new__()` call, including changing all members to a proto member descriptor with a `__set_name__` that will do the final conversion of a member to be an instance of the `Enum` class.
* bpo-41960: Add globalns and localns parameters to inspect.signature and ↵Batuhan Taskaya2020-12-231-49/+31
| | | | Signature.from_callable (GH-22583)
* bpo-17735: inspect.findsource now raises OSError when co_lineno is out of ↵Irit Katriel2020-12-041-1/+6
| | | | | 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-0/+7
|
* bpo-42133: update parts of the stdlib to fall back to `__spec__.loader` when ↵Brett Cannon2020-11-071-2/+5
| | | | `__loader__` is missing (#22929)
* bpo-38605: Make 'from __future__ import annotations' the default (GH-20434)Batuhan Taskaya2020-10-061-2/+17
| | | | | 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-40257: Revert changes to inspect.getdoc() (GH-20073)Serhiy Storchaka2020-05-181-17/+16
|
* bpo-35113: Fix inspect.getsource to return correct source for inner classes ↵Karthikeyan Singaravelan2020-04-181-19/+46
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (#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-16/+17
|
* bpo-39957: Change Signature.parameters to OrderedDict (GH-18988)Jens Reidel2020-03-181-4/+4
|
* bpo-13487: Use sys.modules.copy() in inspect.getmodule() for thread safety. ↵Gregory P. Smith2020-03-051-1/+1
| | | | | | | | (GH-18786) `list(sys.modules.items())` was apparently not immune to "dictionary changed size during iteration" errors. Tested internally using an integration test that has run into this a couple of times in the past two years. With this patch applied, the test is no longer flaky.
* bpo-39775: inspect: Change Signature.parameters back to OrderedDict. (GH-18684)Inada Naoki2020-03-021-10/+12
|