Commit Graph

288 Commits

Author SHA1 Message Date
Jeroen Demeyer fcef60f59d bpo-33261: guard access to __code__ attribute in inspect (GH-6448) 2019-04-02 16:03:42 +02:00
Raymond Hettinger d1e768a677
bpo-36326: Let inspect.getdoc() find docstrings for __slots__ (GH-12498) 2019-03-25 13:01:13 -07:00
Pablo Galindo 7cd2543416
bpo-34890: Make iscoroutinefunction, isgeneratorfunction and isasyncgenfunction work with functools.partial (GH-9903)
inspect.isfunction() processes both inspect.isfunction(func) and
inspect.isfunction(partial(func, arg)) correctly but some other functions in the
inspect module (iscoroutinefunction, isgeneratorfunction and isasyncgenfunction)
lack this functionality. This commits adds a new check in the mentioned functions
in the inspect module so they can work correctly with arbitrarily nested partial
functions.
2018-10-26 12:19:14 +01:00
Chih-Hsuan Yen c57eb9a336 bpo-34871: Fix two typos in test_inspect.py (GH-9698)
`arg` is misspelled as `agr`. I noticed this when playing with https://bugs.python.org/issue34871


https://bugs.python.org/issue34871
2018-10-04 06:15:00 -07:00
Vladimir Matveev 91cb298f81 bpo-6700: Fix inspect.getsourcelines for module level frames/tracebacks (GH-8864) 2018-08-24 17:18:00 +03:00
Matthias Bussonnier 46c5cd0f6e bpo-33582: Emit deprecation warning for `formatargspec` (GH-6994) 2018-06-11 16:08:16 -04:00
Dong-hee Na a9cab433bb bpo-33197: Update a error message of invalid inspect.Parameters. (GH-6636) 2018-05-29 11:04:08 -04:00
Aaron Hall, MBA 4054b172ab bpo-26103: Fix inspect.isdatadescriptor() and a data descriptor definition. (GH-1959)
Look for '__set__' or '__delete__'.
2018-05-21 02:46:42 +03:00
Yury Selivanov 8a387219bd
bpo-33009: Fix inspect.signature() for single-parameter partialmethods. (GH-6004) 2018-03-06 12:59:45 -05:00
larryhastings f36ba12809
bpo-32697: Definition order of kwonly params is now guaranteed preserved. (#5391)
Definition order of kwonly params is now guaranteed preserved.
2018-01-28 11:13:09 -08:00
Serhiy Storchaka d8ac4d1d5a
bpo-31778: Make ast.literal_eval() more strict. (#4035)
Addition and subtraction of arbitrary numbers no longer allowed.
2018-01-04 11:15:39 +02:00
Serhiy Storchaka 3327a2ddf1
bpo-32265: Classify class and static methods of builtin types. (#4776)
Add types.ClassMethodDescriptorType for unbound class methods.
2017-12-15 14:13:41 +02:00
Mike 53f7a7c281 bpo-32297: Few misspellings found in Python source code comments. (#4803)
* Fix multiple typos in code comments

* Add spacing in comments (test_logging.py, test_math.py)

* Fix spaces at the beginning of comments in test_logging.py
2017-12-14 13:04:53 +02:00
Dong-hee Na 762b9571c9 bpo-32018: Fix inspect.signature repr to follow PEP 8 (#4408) 2017-11-15 13:30:59 -05:00
Thomas Kluyver e968bc7357 bpo-30639: Lazily compute repr for error (#2132) 2017-10-24 08:42:36 -04:00
Barry Warsaw 36c1d1f1e5 PEP 553 built-in breakpoint() function (bpo-31353) (#3355)
Implement PEP 553, built-in breakpoint() with support from sys.breakpointhook(), along with documentation and tests.  Closes bpo-31353
2017-10-05 12:11:18 -04:00
Serhiy Storchaka 13ad3b7a82 bpo-31462: Remove trailing whitespaces. (#3564) 2017-09-14 09:38:36 +03:00
Thomas Kluyver f9169ce6b4 bpo-25532: Protect against infinite loops in inspect.unwrap() (#1717)
Some objects (like test mocks) auto-generate new objects on
attribute access, which can lead to an infinite loop in
inspect.unwrap().

Ensuring references are retained to otherwise temporary objects
and capping the size of the memo dict turns this case into a
conventional exception instead.
2017-05-23 13:27:52 +10:00
Dong-hee Na 378d70642a bpo-30149: Fix partialmethod without explicit self parameter (#1308) 2017-05-17 12:00:51 -07:00
Nate fcfe80ec25 bpo-29822: Make inspect.isabstract() work during __init_subclass__. (#678)
At the time when an abstract base class' __init_subclass__ runs,
ABCMeta.__new__ has not yet finished running, so in the presence of
__init_subclass__, inspect.isabstract() can no longer depend only on
TPFLAGS_IS_ABSTRACT.
2017-04-24 20:06:15 +03:00
Marco Buttu 3f2155ffe6 bpo-16355: Clarify when inspect.getcomments() returns None (#428)
Initial patch by Vajrasky Kok.
2017-03-17 11:50:23 +03:00
Berker Peksag 6215e524a2 Issue #15812: Merge from 3.6 2017-01-02 07:00:29 +03:00
Berker Peksag 01debaccdd Issue #15812: Merge from 3.5 2017-01-02 06:59:12 +03:00
Berker Peksag ff0e3b7a54 Issue #15812: inspect.getframeinfo() now correctly shows the first line of a context
Patch by Sam Breese.
2017-01-02 06:57:43 +03:00
Serhiy Storchaka 70d28a184c Remove unused imports. 2016-12-16 20:00:15 +02:00
Yury Selivanov eb6364557f Issue #28003: Implement PEP 525 -- Asynchronous Generators. 2016-09-08 22:01:51 -07:00
Nick Coghlan b4b966ece2 Issue #19611: handle implicit parameters in inspect.signature
inspect.signature now reports the implicit ``.0`` parameters generated by
the compiler for comprehension and generator expression scopes as if they
were positional-only parameters called ``implicit0``.

Patch by Jelle Zijlstra.
2016-06-04 14:40:03 -07:00
Yury Selivanov 06495ffe93 Merge 3.5 (issue #26347) 2016-03-02 11:08:05 -05:00
Yury Selivanov f9e1f2bda9 inspect: Fix BoundArguments.apply_defaults to handle empty arguments
Patch by Frederick Wagner (issue #26347)
2016-03-02 11:07:47 -05:00
Victor Stinner 51d8c526d5 Replace noop constant statement with expression
* Constant statements will be ignored and the compiler will emit a
  SyntaxWarning.
* Replace constant statement (ex: "1") with an expression statement
  (ex: "x=1").
* test_traceback: use context manager on the file.

Issue #26204.
2016-02-08 17:57:02 +01:00
Victor Stinner 9def284387 subprocess._optim_args_from_interpreter_flags()
Issue #26100:

* Add subprocess._optim_args_from_interpreter_flags()
* Add test.support.optim_args_from_interpreter_flags()
* Use new functions in distutils, test_cmd_line_script, test_compileall and
  test_inspect

The change enables test_details() test of test_inspect when -O or -OO command
line option is used.
2016-01-18 12:15:08 +01:00
Yury Selivanov 37dc2b2883 Issue #25486: Resurrect inspect.getargspec in 3.6. Backout a565aad5d6e1.
The decision is that we shouldn't remove popular APIs (however long they
are depreacted) from Python 3, while 2.7 is still around and supported.
2016-01-11 15:15:01 -05:00
Serhiy Storchaka 6230235e83 Issue #25503: Fixed inspect.getdoc() for inherited docstrings of properties.
Original patch by John Mark Vandenberg.
2015-10-29 08:17:10 +02:00
Serhiy Storchaka ac4bdcc80e Issue #25503: Fixed inspect.getdoc() for inherited docstrings of properties.
Original patch by John Mark Vandenberg.
2015-10-29 08:15:50 +02:00
Berker Peksag fa3922cfd0 Issue #13248: Delete remaining references of inspect.getargspec().
Noticed by Yaroslav Halchenko.
2015-07-31 04:11:29 +03:00
Meador Inge f98c35a816 Issue #24485: Function source inspection fails on closures.
The fix for Issue #21217 introduced a regression that caused
`inspect.getsource` to return incorrect results on nested
functions.  The root cause of the regression was due to
switching the implementation to analyze the underlying
bytecode instead of the source code.

This commit switches things back to analyzing the source code
in a more complete way.  The original bug and the regression
are both fixed by the new source code analysis.
2015-07-23 22:52:49 -05:00
Meador Inge 5b718d7f4f Issue #24485: Function source inspection fails on closures.
The fix for Issue #21217 introduced a regression that caused
`inspect.getsource` to return incorrect results on nested
functions.  The root cause of the regression was due to
switching the implementation to analyze the underlying
bytecode instead of the source code.

This commit switches things back to analyzing the source code
in a more complete way.  The original bug and the regression
are both fixed by the new source code analysis.
2015-07-23 22:49:37 -05:00
Yury Selivanov f1b5ccb993 Issue #13248: Remove inspect.getargspec from 3.6 (deprecated from 3.0) 2015-07-23 17:36:02 +03:00
Yury Selivanov 4f4913b38b Issue #24485: Revert backwards compatibility breaking changes of #21217. 2015-07-23 17:10:00 +03:00
Yury Selivanov e4e811d65b Issue #24669: Fix inspect.getsource() for 'async def' functions.
Patch by Kai Groner.
2015-07-21 19:01:52 +03:00
Serhiy Storchaka 2489bd5d4e Issue #24206: Fixed __eq__ and __ne__ methods of inspect classes. 2015-07-18 23:20:50 +03:00
Serhiy Storchaka 3018cc49e8 Issue #24206: Fixed __eq__ and __ne__ methods of inspect classes. 2015-07-18 23:19:05 +03:00
Yury Selivanov fdbeb2b4b6 Issue #24400: Resurrect inspect.isawaitable()
collections.abc.Awaitable and collections.abc.Coroutine no longer
use __instancecheck__ hook to detect generator-based coroutines.

inspect.isawaitable() can be used to detect generator-based coroutines
and to distinguish them from regular generator objects.
2015-07-03 13:11:35 -04:00
Yury Selivanov 59a3b6764c Issue #24541: Drop test_inspect.test_eightteen unittest; update docs
Suggested by Martin Panter.
2015-06-30 22:06:42 -04:00
Yury Selivanov 22f68d5dd6 Issue #24541: Update comment in test_inspect.test_eightteen 2015-06-30 21:44:52 -04:00
Yury Selivanov 8a8f453c5a Issue #24400: Fix failing unittest 2015-06-30 21:18:27 -04:00
Yury Selivanov a74b5e59af Issue #24400: Remove inspect.isawaitable().
isawaitable() was added before collections.abc.Awaitable; now,
with Awaitable, it is no longer needed (we don't have ishashable()
or isiterable() methods in the inspect module either).
2015-06-30 18:19:01 -04:00
Yury Selivanov 5376ba9630 Issue #24400: Introduce a distinct type for 'async def' coroutines.
Summary of changes:

1. Coroutines now have a distinct, separate from generators
   type at the C level: PyGen_Type, and a new typedef PyCoroObject.
   PyCoroObject shares the initial segment of struct layout with
   PyGenObject, making it possible to reuse existing generators
   machinery.  The new type is exposed as 'types.CoroutineType'.

   As a consequence of having a new type, CO_GENERATOR flag is
   no longer applied to coroutines.

2. Having a separate type for coroutines made it possible to add
   an __await__ method to the type.  Although it is not used by the
   interpreter (see details on that below), it makes coroutines
   naturally (without using __instancecheck__) conform to
   collections.abc.Coroutine and collections.abc.Awaitable ABCs.

   [The __instancecheck__ is still used for generator-based
   coroutines, as we don't want to add __await__ for generators.]

3. Add new opcode: GET_YIELD_FROM_ITER.  The opcode is needed to
   allow passing native coroutines to the YIELD_FROM opcode.

   Before this change, 'yield from o' expression was compiled to:

      (o)
      GET_ITER
      LOAD_CONST
      YIELD_FROM

   Now, we use GET_YIELD_FROM_ITER instead of GET_ITER.

   The reason for adding a new opcode is that GET_ITER is used
   in some contexts (such as 'for .. in' loops) where passing
   a coroutine object is invalid.

4. Add two new introspection functions to the inspec module:
   getcoroutinestate(c) and getcoroutinelocals(c).

5. inspect.iscoroutine(o) is updated to test if 'o' is a native
   coroutine object.  Before this commit it used abc.Coroutine,
   and it was requested to update inspect.isgenerator(o) to use
   abc.Generator; it was decided, however, that inspect functions
   should really be tailored for checking for native types.

6. sys.set_coroutine_wrapper(w) API is updated to work with only
   native coroutines.  Since types.coroutine decorator supports
   any type of callables now, it would be confusing that it does
   not work for all types of coroutines.

7. Exceptions logic in generators C implementation was updated
   to raise clearer messages for coroutines:

   Before: TypeError("generator raised StopIteration")
   After: TypeError("coroutine raised StopIteration")
2015-06-22 12:19:30 -04:00
Yury Selivanov bf304fcb32 Issue #23934: Fix inspect.signature to fail correctly for builtin types.
Initial patch by James Powell.
2015-05-30 17:08:36 -04:00
Yury Selivanov 507cd3cf91 Issue 24298: Fix signature() to properly unwrap wrappers around bound methods 2015-05-27 21:59:03 -04:00
Yury Selivanov 46c759d76d Issue 24298: Fix signature() to properly unwrap wrappers around bound methods 2015-05-27 21:56:53 -04:00
Yury Selivanov 3cfec2e2fc Issue 20438: Deprecate inspect.getargspec() and friends. 2015-05-22 11:38:38 -04:00
Yury Selivanov 095fb84fc2 Issue 23898: Fix inspect.classify_class_attrs() to work with __eq__
Patch by Mike Bayer.
2015-05-21 15:45:08 -04:00
Yury Selivanov bf341fb5f6 Issue 23898: Fix inspect.classify_class_attrs() to work with __eq__ 2015-05-21 15:41:57 -04:00
Yury Selivanov 57c74fca02 Issue 24248: Deprecate inspect.Signature.from_function and .from_builtin 2015-05-20 23:07:02 -04:00
Yury Selivanov bcd4fc161a Issue 20691: Add follow_wrapped arg to inspect.signature/from_callable. 2015-05-20 14:30:08 -04:00
Yury Selivanov 8687275358 Issue 24205: Improve inspect.Signature.bind() error messages. 2015-05-19 00:27:49 -04:00
Yury Selivanov b907a513c8 Issue 24190: Add inspect.BoundArguments.apply_defaults() method. 2015-05-16 13:45:09 -04:00
Yury Selivanov 6738b1157a Issue 24208: Fix tests -- don't create a tempdir in __init__. 2015-05-16 10:10:21 -04:00
Yury Selivanov 0cd2bf46ba Issue 24200: Fix broken unittest. 2015-05-15 12:55:20 -04:00
Yury Selivanov f229bc5c53 inspect: Remove "0x..." IDs from Signature objects' __repr__
Issue 24200.
2015-05-15 12:53:56 -04:00
Yury Selivanov 3f6538fed0 Issue 22547: Implement informative __repr__ for inspect.BoundArguments 2015-05-14 18:47:17 -04:00
Yury Selivanov 4cfd4eac7d inspect: Test that BoundArguments.__eq__ repects the order of params 2015-05-14 18:30:27 -04:00
Yury Selivanov 7544508f02 PEP 0492 -- Coroutines with async and await syntax. Issue #24017. 2015-05-11 22:57:16 -04:00
Berker Peksag ce643913a9 Issue #9517: Move script_helper to the support package.
Patch by Christie Wilson.
2015-05-06 06:33:17 +03:00
Antoine Pitrou a8723a02ea Issue #21217: inspect.getsourcelines() now tries to compute the start and
end lines from the code object, fixing an issue when a lambda function is
used as decorator argument.  Patch by Thomas Ballinger.
2015-04-15 00:41:29 +02:00
Zachary Ware 8ef887ce47 Issue #20586: Argument Clinic now ensures signatures on functions without docstrings. 2015-04-13 18:22:35 -05:00
Nick Coghlan 9c680b0728 Actually run the builtins Argument Clinic test 2015-04-13 12:54:54 -04:00
Serhiy Storchaka 5cf2b7253d Issue #15582: inspect.getdoc() now follows inheritance chains. 2015-04-03 22:38:53 +03:00
Serhiy Storchaka c2ccce791c Issue #23641: Cleaned out legacy dunder names from tests and docs.
Fixed 2 to 3 porting bug in pynche.ColorDB.
Added few tests for __truediv__, __floordiv__ and __matmul__.
2015-03-12 22:01:30 +02:00
Serhiy Storchaka a60c2fe480 Issue #23641: Cleaned out legacy dunder names from tests and docs.
Fixed 2 to 3 porting bug in pynche.ColorDB.
2015-03-12 21:56:08 +02:00
Yury Selivanov 7de29687f2 inspect: Fix getsource() to load updated source of reloaded module
Issue #1218234. Initial patch by Berker Peksag.
2014-12-08 18:00:25 -05:00
Yury Selivanov ef1e750225 inspect: Fix getsource() to load updated source of reloaded module
Issue #1218234. Initial patch by Berker Peksag.
2014-12-08 16:05:34 -05:00
R David Murray b55f944fa9 Merge: #12780: update inspect test skipIf for PEP 3147. 2014-10-03 11:16:08 -04:00
R David Murray 32562d7da3 #12780: update inspect test skipIf for PEP 3147.
The test needs to be skipped if unicodedata is either part of the
main binary (a repackaging of cpython on Windows?) or has python
source (pypy?).  PEP 3147 makes __file__ point to the .py source,
so we need to change the extension check from looking for the
old .pyc/.pyo to just looking for .py.

Note that this skip should never trigger on CPython itself, so
one could argue it should be dropped instead.  But since it exists,
why risk breaking someone else's python.
2014-10-03 11:15:38 -04:00
Yury Selivanov 081bbf6b28 inspect: Fix getsource() to support decorated functions.
Issue #1764286. Patch by Claudiu Popa.
2014-09-26 17:34:54 -04:00
Yury Selivanov 08d4a4f488 inspect.Signature: Fix discrepancy between __eq__ and __hash__.
Issue #20334. Thanks to Antony Lee for bug report & initial patch.
2014-09-12 15:48:02 -04:00
Antoine Pitrou cdcafb78b2 Issue #16808: inspect.stack() now returns a named tuple instead of a tuple.
Patch by Daniel Shahaf.
2014-08-24 10:50:28 -04:00
Nick Coghlan f9e227e5a9 Issue #20184: Add signature introspection for 30 of the builtins
Also adds a test to test_inspect to track progress on builtin
introspection support, to ensure it doesn't regress in the future.
2014-08-17 14:01:19 +10:00
Yury Selivanov 42407abe24 inspect: Validate that __signature__ is None or an instance of Signature.
Closes #21801.
2014-06-23 10:23:50 -07:00
Yury Selivanov c0f964fd55 inspect: Validate that __signature__ is None or an instance of Signature.
Closes #21801.
2014-06-23 10:21:04 -07:00
Yury Selivanov 67ae50ee1c inspect: Make Signature and Parameter hashable. Issue #20334. 2014-04-08 11:46:50 -04:00
Yury Selivanov 3f73ca23cf inspect.signautre: Fix functools.partial support. Issue #21117 2014-04-08 11:30:45 -04:00
Yury Selivanov 0fceaf45e2 inspect.signautre: Fix functools.partial support. Issue #21117 2014-04-08 11:28:02 -04:00
Yury Selivanov dccfa13cdb inspect: Fix getcallargs() to fail correctly if more than 3 args are missing.
Patch by Jeremiah Lowin. Closes #20817.
2014-03-27 18:42:52 -04:00
Yury Selivanov 2542b66bb0 inspect: Fix getcallargs() to fail correctly if more than 3 args are missing.
Patch by Jeremiah Lowin. Closes #20817.
2014-03-27 18:42:52 -04:00
Yury Selivanov 875df20e8a inspect: Fix getcallargs() to raise correct TypeError
... for missing keyword-only arguments. Patch by Jeremiah Lowin.
Closes #20816.
2014-03-27 18:23:03 -04:00
Yury Selivanov b1d060bf8b inspect: Fix getcallargs() to raise correct TypeError
... for missing keyword-only arguments. Patch by Jeremiah Lowin.
Closes #20816.
2014-03-27 18:23:03 -04:00
Yury Selivanov 374375dd26 inspect.signature: Improve repr of Signature and Parameter. Closes #20378 2014-03-27 12:41:53 -04:00
Yury Selivanov da39645ad3 inspect.Signature: Add 'Signature.from_callable' classmethod. Closes #17373 2014-03-27 12:09:24 -04:00
Yury Selivanov a5d63dd7b8 inspect.signature: Make Signature and Parameter picklable. Closes #20726 2014-03-27 11:31:43 -04:00
Yury Selivanov d930d85f12 Issue #20786: Fix signatures for dict.__delitem__ and property.__delete__ 2014-03-02 12:25:27 -05:00
Yury Selivanov 056e265491 Issue #20786: Fix signatures for dict.__delitem__ and property.__delete__ 2014-03-02 12:25:27 -05:00
Yury Selivanov a773de040d inspect.signature: Check for function-like objects before builtins. Issue #17159 2014-02-21 18:30:53 -05:00
Yury Selivanov 8c185ee12e inspect: Fix getfullargspec to support builtin module-level functions. Issue #20711 2014-02-21 01:32:42 -05:00
Yury Selivanov 57d240ef64 inspect: Fix getfullargspec() to not to follow __wrapped__ chains
Initial patch by Nick Coghlan.
2014-02-19 16:27:23 -05:00
Yury Selivanov 34ce99f66d Mangle __parameters in __annotations__ dict properly. Issue #20625. 2014-02-18 12:49:41 -05:00
Yury Selivanov 8dfb4576a9 inspect.signature: Check for function-like objects before builtins. Issue #17159 2014-02-21 18:30:53 -05:00
Yury Selivanov d224b6a796 inspect: Fix getfullargspec to support builtin module-level functions. Issue #20711 2014-02-21 01:32:42 -05:00
Yury Selivanov ff385b89f4 inspect: Fix getfullargspec() to not to follow __wrapped__ chains
Initial patch by Nick Coghlan.
2014-02-19 16:27:23 -05:00