summaryrefslogtreecommitdiffstats
path: root/Lib/inspect.py
Commit message (Collapse)AuthorAgeFilesLines
* gh-108751: Add copy.replace() function (GH-108752)Serhiy Storchaka2023-09-061-0/+4
| | | | | | | | | It creates a modified copy of an object by calling the object's __replace__() method. It is a generalization of dataclasses.replace(), named tuple's _replace() method and replace() methods in various classes, and supports all these stdlib classes.
* gh-106727: Add `__module__` check for `inspect.getsource(cls)` (#106968)Tian Gao2023-07-241-1/+2
|
* gh-106727: Make `inspect.getsource` smarter for class for same name ↵Tian Gao2023-07-181-11/+46
| | | | definitions (#106815)
* gh-81283: compiler: remove indent from docstring (#106411)Inada Naoki2023-07-151-23/+22
| | | Co-authored-by: Éric <merwok@netwok.org>
* gh-105080: Fixed inconsistent signature on derived classes (#105217)Tian Gao2023-06-021-11/+12
|
* gh-105069: Add a readline-like callable to the tokenizer to consume input ↵Pablo Galindo Salgado2023-05-301-1/+1
| | | | iteratively (#105070)
* gh-105013: Fix inspect.getsource with parenthesized multiline lambdas (#105021)Pablo Galindo Salgado2023-05-271-0/+8
|
* gh-102856: Python tokenizer implementation for PEP 701 (#104323)Marta Gómez Macías2023-05-211-2/+2
| | | | | | | | | | | This commit replaces the Python implementation of the tokenize module with an implementation that reuses the real C tokenizer via a private extension module. The tokenize module now implements a compatibility layer that transforms tokens from the C tokenizer into Python tokenize tokens for backward compatibility. As the C tokenizer does not emit some tokens that the Python tokenizer provides (such as comments and non-semantic newlines), a new special mode has been added to the C tokenizer mode that currently is only used via the extension module that exposes it to the Python layer. This new mode forces the C tokenizer to emit these new extra tokens and add the appropriate metadata that is needed to match the old Python implementation. Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
* gh-75367: Fix data descriptor detection in inspect.getattr_static (#104517)Furkan Onder2023-05-161-2/+4
| | | Co-authored-by: Carl Meyer <carl@oddbird.net>
* gh-103193: cache calls to `inspect._shadowed_dict` in ↵Alex Waygood2023-05-071-2/+6
| | | | | `inspect.getattr_static` (#104267) Co-authored-by: Carl Meyer <carl@oddbird.net>
* gh-102500: Implement PEP 688 (#102521)Jelle Zijlstra2023-05-041-0/+23
| | | Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
* gh-102799: replace sys.exc_info by sys.exception in inspect and traceback ↵Irit Katriel2023-05-011-1/+3
| | | | modules (#104032)
* gh-103556: [inspect.Signature] disallow pos-or-kw params without default ↵Nikita Sobolev2023-04-221-6/+4
| | | | after pos-only with default (#103557)
* gh-103193: Speedup and inline `inspect._is_type` (#103321)Alex Waygood2023-04-061-9/+4
| | | Improve performance of `inspect.getattr_static`
* gh-103193: Use LBYL idioms rather than EAFP in `inspect.getattr_static` ↵Alex Waygood2023-04-061-15/+10
| | | | (#103318)
* gh-103193: Micro-optimise helper functions for `inspect.getattr_static` ↵Alex Waygood2023-04-051-4/+3
| | | | (#103195)
* gh-79940: add introspection API for asynchronous generators to `inspect` ↵Thomas Krennwallner2023-03-111-0/+50
| | | | module (#11590)
* gh-102378: don't bother stripping `/` from __text_signature__ (#102379)David Hewitt2023-03-091-40/+17
|
* gh-102302 Micro-optimize `inspect.Parameter.__hash__` (#102303)Gouvernathor2023-03-041-1/+1
|
* 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
|