summaryrefslogtreecommitdiffstats
path: root/Lib/inspect.py
Commit message (Collapse)AuthorAgeFilesLines
* gh-121027: Add a future warning in functools.partial.__get__ (#121086)Serhiy Storchaka2024-06-271-4/+4
|
* gh-120381: Fix inspect.ismethoddescriptor() (#120383)Jan Kaliszewski2024-06-181-4/+7
| | | | | | | | The `inspect.ismethoddescriptor()` function did not check for the lack of `__delete__()` and, consequently, erroneously returned True when applied to *data* descriptors with only `__get__()` and `__delete__()` defined. Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
* gh-114053: Fix bad interaction of PEP 695, PEP 563 and ↵Alex Waygood2024-06-131-1/+7
| | | | `inspect.get_annotations` (#120270)
* gh-119180: PEP 649 compiler changes (#119361)Jelle Zijlstra2024-06-111-7/+1
|
* gh-120200: Fix `inspect.iscoroutinefunction(inspect) is True` corner case ↵Nikita Sobolev2024-06-071-3/+3
| | | | (#120214)
* gh-87106: Fix inspect.signature.bind() handling of positional-only arguments ↵Jacob Walls2024-05-131-12/+16
| | | | with **kwargs (GH-103404)
* gh-118465: Add __firstlineno__ attribute to class (GH-118475)Serhiy Storchaka2024-05-061-78/+5
| | | | It is set by compiler with the line number of the first line of the class definition.
* gh-82062: Fix support of parameter defaults on methods in extension modules ↵Sergey B Kirpichev2024-05-021-0/+5
| | | | | | | | | (GH-115270) Now inspect.signature() supports references to the module globals in parameter defaults on methods in extension modules. Previously it was only supported in functions. The workaround was to specify the fully qualified name, including the module name.
* gh-118404: Fix inspect.signature() for non-comparable callables (GH-118405)Serhiy Storchaka2024-04-301-2/+4
|
* gh-118285: Fix signatures of operator.{attrgetter,itemgetter,methodcaller} ↵Serhiy Storchaka2024-04-291-0/+7
| | | | | | | | | instances (GH-118316) * Allow to specify the signature of custom callable instances of extension type by the __text_signature__ attribute. * Specify signatures of operator.attrgetter, operator.itemgetter, and operator.methodcaller instances.
* gh-118013: Use weakrefs for the cache key in `inspect._shadowed_dict` (#118202)Alex Waygood2024-04-241-3/+22
|
* gh-116987: Support class code objects in inspect.findsource() (GH-117025)Tian Gao2024-03-211-9/+2
|
* gh-114099 - Add iOS framework loading machinery. (GH-116454)Russell Keith-Magee2024-03-191-1/+6
| | | | Co-authored-by: Malcolm Smith <smith@chaquo.com> Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
* gh-101293: Fix support of custom callables and types in ↵Serhiy Storchaka2024-03-011-87/+74
| | | | | | | | | | | inspect.Signature.from_callable() (GH-115530) Support callables with the __call__() method and types with __new__() and __init__() methods set to class methods, static methods, bound methods, partial functions, and other types of methods and descriptors. Add tests for numerous types of callables and descriptors.
* gh-112006: Fix inspect.unwrap() for types where __wrapped__ is a data ↵Serhiy Storchaka2024-02-261-7/+3
| | | | | | descriptor (GH-115540) This also fixes inspect.Signature.from_callable() for builtins classmethod() and staticmethod().
* gh-101860: Expose __name__ on property (GH-101876)Eugene Toder2024-02-201-3/+2
| | | | | Useful for introspection and consistent with functions and other descriptors.
* bpo-38364: unwrap partialmethods just like we unwrap partials (#16600)Martijn Pieters2024-02-151-2/+4
| | | | | | | | | | | | | * bpo-38364: unwrap partialmethods just like we unwrap partials The inspect.isgeneratorfunction, inspect.iscoroutinefunction and inspect.isasyncgenfunction already unwrap functools.partial objects, this patch adds support for partialmethod objects as well. Also: Rename _partialmethod to __partialmethod__. Since we're checking this attribute on arbitrary function-like objects, we should use the namespace reserved for core Python. --------- Co-authored-by: Petr Viktorin <encukou@gmail.com>
* gh-112316: improve docs for `inspect.signature` and `inspect.Signature` ↵Alex Waygood2023-12-031-1/+1
| | | | (#112631)
* gh-112139: Add `inspect.Signature.format` and use it in `pydoc` (#112143)Nikita Sobolev2023-12-021-0/+12
| | | Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* 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.