Commit graph

311 commits

Author SHA1 Message Date
Miss Islington (bot)
b153cab6d8
[3.12] gh-108303: Move ann_module*.py files to typinganndata/ folder (GH-108354) (#109672)
gh-108303: Move `ann_module*.py` files to `typinganndata/` folder (GH-108354)
(cherry picked from commit 3f61cf646d)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2023-10-02 17:10:33 +02:00
Miss Islington (bot)
d3922c4688
[3.12] gh-105080: Fixed inconsistent signature on derived classes (GH-105217) (#105257)
gh-105080: Fixed inconsistent signature on derived classes (GH-105217)
(cherry picked from commit 9ad199ba36)

Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
2023-06-02 17:05:49 -06:00
Miss Islington (bot)
2f8c22f1d6
[3.12] gh-105042: Disable unmatched parens syntax error in python tokenize (GH-105061) (#105120)
gh-105042: Disable unmatched parens syntax error in python tokenize (GH-105061)
(cherry picked from commit 70f315c2d6)

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
2023-05-31 11:11:39 +01:00
Miss Islington (bot)
41b622b1e8
[3.12] gh-105013: Fix inspect.getsource with parenthesized multiline lambdas (GH-105021) (#105032)
gh-105013: Fix inspect.getsource with parenthesized multiline lambdas (GH-105021)
(cherry picked from commit 3a5be878be)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2023-05-28 12:18:43 +01:00
Miss Islington (bot)
3158b4d2f9
[3.12] gh-104955: Fix __release_buffer__ signature (GH-104956) (#104973)
(cherry picked from commit 6e1eccdcce)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
2023-05-26 13:15:08 +00:00
Furkan Onder
5e9f471e7d
gh-75367: Fix data descriptor detection in inspect.getattr_static (#104517)
Co-authored-by: Carl Meyer <carl@oddbird.net>
2023-05-16 17:34:44 +00:00
Carl Meyer
c3b595e73e
gh-97933: (PEP 709) inline list/dict/set comprehensions (#101441)
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2023-05-09 11:02:14 -06:00
Alex Waygood
921185ed05
gh-103193: Improve getattr_static test coverage (#104286) 2023-05-08 15:18:36 +01:00
Alex Waygood
1b19bd1a88
gh-103193: cache calls to inspect._shadowed_dict in inspect.getattr_static (#104267)
Co-authored-by: Carl Meyer <carl@oddbird.net>
2023-05-07 18:45:09 +01:00
Nikita Sobolev
6b58d419a1
gh-103556: [inspect.Signature] disallow pos-or-kw params without default after pos-only with default (#103557) 2023-04-21 23:45:10 -06:00
Nikita Sobolev
4fe1c4b97e
gh-103553: Improve test_inspect: add more assertions, remove unused (#103554) 2023-04-15 13:48:31 -07:00
Nikita Sobolev
7569781176
gh-103406: Modernize pos-only arguments usage in test_signature (#103407) 2023-04-14 00:06:31 -07:00
Irit Katriel
44bd3fe570
gh-102799: use exception instance instead of sys.exc_info() (#102885) 2023-03-31 11:23:02 +01:00
Thomas Krennwallner
534660f168
gh-79940: skip TestGetAsyncGenState on wasm as it requires working sockets (GH-102605)
Skip `TestGetAsyncGenState` and restoring of the default event loop policy in `test_inspect` if platform lacks working socket support.

Fixes #11590

Automerge-Triggered-By: GH:kumaraditya303
2023-03-11 10:36:49 -08:00
Thomas Krennwallner
ced13c96a4
gh-79940: add introspection API for asynchronous generators to inspect module (#11590) 2023-03-11 18:49:40 +05:30
David Hewitt
71cf7c3ddd
gh-102378: don't bother stripping / from __text_signature__ (#102379) 2023-03-09 15:06:20 -08:00
Carlton Gibson
07a87f74fa
gh-94912: Adjusted check for non-standard coroutine function marker. (#100935)
The initial implementation did not correctly identify explicitly
marked class instances.

Follow up to 532aa4e4e0
2023-01-11 13:17:26 -08:00
Nikita Sobolev
9e7d7266ec
gh-96127: Fix inspect.signature call on mocks (#96335) 2023-01-07 10:49:15 +00:00
Shantanu
79311cbfe7
gh-85267: Improvements to inspect.signature __text_signature__ handling (#98796)
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`.
2022-12-20 19:29:02 -08:00
Carlton Gibson
532aa4e4e0
gh-94912: Added marker for non-standard coroutine function detection (#99247)
This introduces a new decorator `@inspect.markcoroutinefunction`,
which, applied to a sync function, makes it appear async to
`inspect.iscoroutinefunction()`.
2022-12-18 11:13:24 -08:00
Ethan Furman
a5a7cea202
gh-100039: enhance __signature__ to work with str and callables (GH-100168)
Callables should be either class- or static-methods.
Enum now uses the classmethod version to greatly improve the help
given for enums and flags.
2022-12-16 12:30:47 -08:00
Carl Meyer
68e41295b8
gh-83035: handle decorator with nested parens in inspect.getsource (#99654) 2022-12-07 08:55:12 -08:00
Anton Ryzhov
dbf2faf579
gh-74044: inspect.signature for wrappers around decorated bound methods (GH-736) 2022-11-10 12:32:01 +00:00
Frazer McLean
f4f8133387
GH-83901: Improve Signature.bind error message for missing keyword-only params (#95347)
Fixes GH-83901
2022-10-07 15:24:17 -07:00
Anh71me
d5fea01d9d
GH-96073: Fix wild replacement in inspect.formatannotation (#96074)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2022-10-07 11:23:06 -07:00
Brett Cannon
e1c4d56fdd
gh-65961: Do not rely solely on __cached__ (GH-97990)
Make sure `__spec__.cached` (at minimum) can be used.
2022-10-06 15:40:22 -07:00
Mehdi ABAAKOUK
4261b6bffc
gh-84753: Make inspect.iscoroutinefunction() work with AsyncMock (#94050)
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>
2022-06-30 19:08:38 +02:00
Christian Heimes
9b50585e02
gh-90473: Skip tests that don't apply to Emscripten and WASI (GH-92846) 2022-05-16 16:02:37 +02:00
Zac Hatfield-Dodds
65f88a6ef7
gh-92062: inspect.Parameter checks whether name is a keyword (GH-92065)
Fixes #92062.
2022-05-03 13:52:30 -07:00
Pablo Galindo Salgado
0daa99f68b
gh-88116: Enhance the inspect frame APIs to use the extended position information (GH-91531) 2022-04-23 03:16:48 +01:00
Hakan Çelik
562c13f573
bpo-29418: Implement inspect.ismethodwrapper and fix inspect.isroutine for cases where methodwrapper is given (GH-19261)
Automerge-Triggered-By: GH:isidentical
2022-02-16 04:46:20 -08:00
Christian Heimes
96b344c2f1
bpo-40280: Address more test failures on Emscripten (GH-31050)
Co-authored-by: Brett Cannon <brett@python.org>
2022-02-05 20:52:01 +01:00
Nikita Sobolev
0cbdd21311
bpo-46565: del loop vars that are leaking into module namespaces (GH-30993) 2022-02-03 11:20:08 +02:00
Weipeng Hong
691506f4e9
bpo-46103: Fix inspect.getmembers to only get __bases__ from class (GH-30147) 2022-01-23 09:40:38 -08:00
Weipeng Hong
881a763cfe
bpo-43118: Fix bug in inspect.signature around 'base.__text_signature__' (GH-30285) 2022-01-21 13:24:33 -08:00
Irit Katriel
a287b31bcb
bpo-46411: Remove unnecessary calls to sys.exc_info() in tests (GH-30638) 2022-01-18 07:05:16 +00:00
AN Long
f62420c3d3
Remove spaces in empty lines (GH-30121) 2021-12-16 01:35:21 +09:00
Kumar Aditya
810c1769f1
bpo-27062: add __all__ to inspect module (GH-30003) 2021-12-11 00:05:23 +01:00
Weipeng Hong
af8c8caaf5
bpo-30533:Add function inspect.getmembers_static that does not call 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>
2021-11-30 10:23:13 -08:00
Irit Katriel
a459a81530
bpo-45406: make inspect.getmodule() return None when getabsfile() raises FileNotFoundError (GH-28824) 2021-11-02 22:55:51 +01:00
Martin Rueckl
d02ffd1b5c
bpo-45438: format of inspect.Signature with generic builtins (#29212)
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>
2021-10-27 14:36:41 -07:00
Hugo van Kemenade
d89fb9a5a6
bpo-45320: Remove long-deprecated inspect methods (GH-28618) 2021-10-20 20:48:55 +02:00
Serhiy Storchaka
40348acc18
bpo-45229: Remove test_main in many tests (GH-28405)
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.
2021-09-19 15:27:33 +03:00
andrei kulakov
58325971de
bpo-44808: fixes test for interactive inspect getsource of a class (GH-27571)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2021-08-03 14:47:30 +02:00
Pablo Galindo Salgado
626d397cc1
bpo-44808: Fix test_inspect in refleak mode (GH-27544) 2021-08-02 13:54:20 +02:00
andrei kulakov
48a62559df
bpo-44648: Fix error type in inspect.getsource() in interactive session (GH-27171) 2021-07-30 19:17:46 +02:00
Weipeng Hong
6aab5f9bf3
bpo-40897:Give priority to using the current class constructor in inspect.signature (#27177)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2021-07-16 15:04:27 +02:00
Anthony Sottile
9e746e3298
bpo-20684: Remove unused inspect._signature_get_bound_param (GH-21100) 2021-05-22 15:51:43 +01:00
larryhastings
74613a46fc
bpo-43817: Add inspect.get_annotations(). (#25522)
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.
2021-04-29 21:16:28 -07:00
Pablo Galindo
b0544ba77c
bpo-38605: Revert making 'from __future__ import annotations' the default (GH-25490)
This reverts commits 044a1048ca and 1be456ae9d, adapting the code to changes that happened after it.
2021-04-21 12:41:19 +01:00